Skip to content

Commit 28d9458

Browse files
committed
Add Psalm; Fix Tests namespace; Upgrade ByJG components
1 parent e9b774a commit 28d9458

30 files changed

+603
-790
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: byjg

.github/workflows/phpunit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ jobs:
1616
strategy:
1717
matrix:
1818
php-version:
19+
- "8.3"
1920
- "8.2"
2021
- "8.1"
21-
- "8.0"
22-
- "7.4"
2322

2423
steps:
2524
- uses: actions/checkout@v4
2625
- run: composer install
26+
- run: ./vendor/bin/psalm
2727
- run: ./vendor/bin/phpunit --stderr
2828

2929
Documentation:

.idea/runConfigurations/Psalm.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![GitHub license](https://img.shields.io/github/license/byjg/php-authuser.svg)](https://opensource.byjg.com/opensource/licensing.html)
77
[![GitHub release](https://img.shields.io/github/release/byjg/php-authuser.svg)](https://github.com/byjg/php-authuser/releases/)
88

9-
A simple and customizable class for enable user authentication inside your application. It is available on XML files, Relational Databases and Moodle.
9+
A simple and customizable class for enable user authentication inside your application. It is available on XML files, Relational Databases.
1010

1111
The main purpose is just to handle all complexity of validate a user, add properties and create access token abstracting the database layer.
1212
This class can persist into session (or file, memcache, etc) the user data between requests.
@@ -34,27 +34,6 @@ $users = new ByJG\Authenticate\UsersDBDataset(
3434
*Note*: See the [Anydataset project](https://github.com/byjg/anydataset#connection-based-on-uri) to see the
3535
database available and the connection strings as well.
3636

37-
Using the Moodle as the user storage:
38-
39-
```php
40-
<?php
41-
$users = new UsersMoodleDataset('connection');
42-
```
43-
44-
## Authenticate a user with your username and password and persist into the session
45-
46-
```php
47-
<?php
48-
$user = $users->isValidUser('someuser', '12345');
49-
if (!is_null($user))
50-
{
51-
$userId = $user->getUserid();
52-
53-
$sessionContext = new \ByJG\Authenticate\SessionContext(\ByJG\Cache\Factory::createSessionPool());
54-
$sessionContext->registerLogin($userId);
55-
}
56-
```
57-
5837
## Check if user was previously authenticated
5938

6039
```php
@@ -151,14 +130,13 @@ If you do not know to create/manage that unique prefix **prefer to use the regul
151130
│ │ │
152131
│ │ │
153132
┌───────────────────┐ ┌───────────────────┐ ┌────────────────────┐
154-
│ UsersAnyDataset │ │ UsersDBDataset │ │ UsersMoodleDataset
133+
│ UsersAnyDataset │ │ UsersDBDataset │ │ xxxxxxxxxxxxxxxxxx
155134
└───────────────────┘ └───────────────────┘ └────────────────────┘
156135
```
157136

158137
- UserInterface contain the basic interface for the concrete implementation
159138
- UsersDBDataset is a concrete implementation to retrieve/save user in a Database
160139
- UserAnyDataset is a concrete implementation to retrieve/save user in a Xml file
161-
- UsersMoodleDatabase is a concrete implementation to retrieve users in a Moodle database structure.
162140
- UserModel is the basic model get/set for the user
163141
- UserPropertyModel is the basic model get/set for extra user property
164142
- UserDefinition will map the model to the database

composer.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
{
22
"name": "byjg/authuser",
3-
"description": "A simple and customizable class for enable user authentication inside your application. It is available on XML files, Relational Databases and Moodle.",
3+
"description": "A simple and customizable class for enable user authentication inside your application. It is available on XML files and Relational Databases.",
44
"autoload": {
55
"psr-4": {
66
"ByJG\\Authenticate\\": "src/"
77
}
88
},
9+
"autoload-dev": {
10+
"psr-4": {
11+
"Tests\\": "tests/"
12+
}
13+
},
914
"minimum-stability": "dev",
1015
"prefer-stable": true,
1116
"require": {
12-
"php": ">=7.4",
13-
"byjg/micro-orm": "4.9.*",
14-
"byjg/cache-engine": "4.9.*",
15-
"byjg/jwt-wrapper": "5.0.x.dev"
17+
"php": ">=8.1",
18+
"byjg/micro-orm": "^5.0",
19+
"byjg/cache-engine": "^5.0",
20+
"byjg/jwt-wrapper": "^5.0"
1621
},
1722
"require-dev": {
18-
"phpunit/phpunit": "5.7.*|7.4.*|^9.5"
23+
"phpunit/phpunit": "^9.6",
24+
"vimeo/psalm": "^5.9"
1925
},
2026
"license": "MIT"
2127
}

psalm.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
4+
resolveFromConfigFile="true"
5+
findUnusedBaselineEntry="true"
6+
findUnusedCode="false"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xmlns="https://getpsalm.org/schema/config"
9+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
10+
>
11+
<projectFiles>
12+
<directory name="src" />
13+
<directory name="tests" />
14+
<ignoreFiles>
15+
<directory name="vendor" />
16+
</ignoreFiles>
17+
</projectFiles>
18+
</psalm>

src/Definition/PasswordDefinition.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace ByJG\Authenticate\Definition;
44

5+
use InvalidArgumentException;
6+
57
class PasswordDefinition
68
{
79
const MINIMUM_CHARS = "minimum_chars";
@@ -13,7 +15,7 @@ class PasswordDefinition
1315
const ALLOW_SEQUENTIAL = "allow_sequential";
1416
const ALLOW_REPEATED = "allow_repeated";
1517

16-
protected $rules = [];
18+
protected array $rules = [];
1719

1820
public function __construct($rules = null)
1921
{
@@ -32,28 +34,28 @@ public function __construct($rules = null)
3234
}
3335
}
3436

35-
public function setRule($rule, $value)
37+
public function setRule(string $rule, string|bool|int $value): void
3638
{
3739
if (!array_key_exists($rule, $this->rules)) {
38-
throw new \InvalidArgumentException("Invalid rule");
40+
throw new InvalidArgumentException("Invalid rule");
3941
}
4042
$this->rules[$rule] = $value;
4143
}
4244

43-
public function getRules()
45+
public function getRules(): array
4446
{
4547
return $this->rules;
4648
}
4749

48-
public function getRule($rule)
50+
public function getRule($rule): string|bool|int
4951
{
5052
if (!array_key_exists($rule, $this->rules)) {
51-
throw new \InvalidArgumentException("Invalid rule");
53+
throw new InvalidArgumentException("Invalid rule");
5254
}
5355
return $this->rules[$rule];
5456
}
5557

56-
public function matchPassword($password)
58+
public function matchPassword(string $password): bool
5759
{
5860
// match password against the rules
5961
if (strlen($password) < $this->rules[self::MINIMUM_CHARS]) {

0 commit comments

Comments
 (0)