From 89bcfa031ba900b474e9efff0a612b00a05d354b Mon Sep 17 00:00:00 2001 From: s3b4stian Date: Wed, 13 Dec 2023 10:12:02 +0100 Subject: [PATCH] PHPstan fixes --- src/Linna/Authorization/PermissionExtended.php | 2 ++ src/Linna/Authorization/Role.php | 11 ++++++----- src/Linna/Authorization/UserExtended.php | 3 ++- src/Linna/Cache/RedisCache.php | 4 ++++ .../Authentication/EnhancedAuthenticationTest.php | 6 +++--- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Linna/Authorization/PermissionExtended.php b/src/Linna/Authorization/PermissionExtended.php index e520542..b89de33 100644 --- a/src/Linna/Authorization/PermissionExtended.php +++ b/src/Linna/Authorization/PermissionExtended.php @@ -29,6 +29,8 @@ class PermissionExtended extends Permission * @param string $name Permission name. * @param string $description Permission description. * @param integer $inherited Specify if the permission is inherited from a group. + * @param array $users Users who hold the specific permission. + * @param array $roles Roles who hold the specific permission. * @param DateTimeImmutable|null $created Creation datetime. * @param DateTimeImmutable|null $lastUpdate Last updated datetime. */ diff --git a/src/Linna/Authorization/Role.php b/src/Linna/Authorization/Role.php index 4eacbb0..0726764 100644 --- a/src/Linna/Authorization/Role.php +++ b/src/Linna/Authorization/Role.php @@ -24,11 +24,12 @@ class Role extends DomainObjectAbstract /** * Constructor. * - * @param string $name The name of the role. - * @param string $description The description of the role. - * @param integer $active Specify is the role is atctive. - * @param array $users Users in role. - * @param array $permissions Permissions granted by the role. + * @param null|int|string $id Permission id. + * @param string $name The name of the role. + * @param string $description The description of the role. + * @param integer $active Specify is the role is atctive. + * @param DateTimeImmutable|null $created Creation datetime. + * @param DateTimeImmutable|null $lastUpdate Last updated datetime. */ public function __construct( //role id diff --git a/src/Linna/Authorization/UserExtended.php b/src/Linna/Authorization/UserExtended.php index 33a679a..4025a74 100644 --- a/src/Linna/Authorization/UserExtended.php +++ b/src/Linna/Authorization/UserExtended.php @@ -41,7 +41,7 @@ class UserExtended extends User */ public function __construct( /** @var Password Password class for manage password. */ - private Password $passwordUtility = new Password(), + Password $passwordUtility = new Password(), //user id null|int|string $id = null, @@ -82,6 +82,7 @@ public function __construct( id: $id, uuid: $uuid, name: $name, + email: $email, description: $description, password: $password, active: $active, diff --git a/src/Linna/Cache/RedisCache.php b/src/Linna/Cache/RedisCache.php index a3759d1..843d58a 100644 --- a/src/Linna/Cache/RedisCache.php +++ b/src/Linna/Cache/RedisCache.php @@ -161,6 +161,10 @@ public function clear(): bool */ public function has(string $key): bool { + //https://github.com/phpredis/phpredis#exists + //PHPstan should not trigger the error because ecists return only a long and + //$this->redis is surely an instance of Redis class + /** @phpstan-ignore-next-line */ if ($this->redis->exists($key) > 0) { return true; } diff --git a/tests/Linna/Authentication/EnhancedAuthenticationTest.php b/tests/Linna/Authentication/EnhancedAuthenticationTest.php index dfc6b39..04e5220 100644 --- a/tests/Linna/Authentication/EnhancedAuthenticationTest.php +++ b/tests/Linna/Authentication/EnhancedAuthenticationTest.php @@ -126,7 +126,7 @@ public function testGetAttemptsLeftWithSameUser(): void $sessionId = 'mbvi2lgdpcj6vp3qemh2estei2'; $ipAddress = '192.168.1.2'; - for ($i = 0; $i < 4; $i++){ + for ($i = 0; $i < 4; $i++) { $this->storeLoginAttempt($user, $sessionId, $ipAddress); } @@ -151,7 +151,7 @@ public function testGetAttemptsLeftWithSameSession(): void $sessionId = 'vaqgvpochtif8gh888q6vnlch5'; $ipAddress = '192.168.1.3'; - for ($i = 0; $i < 9; $i++){ + for ($i = 0; $i < 9; $i++) { $this->storeLoginAttempt($user, $sessionId, $ipAddress); } @@ -176,7 +176,7 @@ public function testGetAttemptsLeftWithSameIp(): void $sessionId = '3hto06tko273jjc1se0v1aqvvn'; $ipAddress = '192.168.1.4'; - for ($i = 0; $i < 19; $i++){ + for ($i = 0; $i < 19; $i++) { $this->storeLoginAttempt($user, $sessionId, $ipAddress); }