Skip to content

Commit 056aae0

Browse files
authored
Merge pull request codeigniter4#1330 from datamweb/fix-phpstan-error
chore(phpstan): use unsealed array shapes for credentials
2 parents e0d98be + 0c82a64 commit 056aae0

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

phpstan-baseline.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@
6868
'path' => __DIR__ . '/src/Authentication/Authenticators/JWT.php',
6969
];
7070
$ignoreErrors[] = [
71-
'rawMessage' => 'Parameter #1 $credentials (array{token?: string}) of method CodeIgniter\\Shield\\Authentication\\Authenticators\\JWT::attempt() should be contravariant with parameter $credentials (array) of method CodeIgniter\\Shield\\Authentication\\AuthenticatorInterface::attempt()',
71+
'rawMessage' => 'Parameter #1 $credentials (array{token?: string, ...}) of method CodeIgniter\\Shield\\Authentication\\Authenticators\\JWT::attempt() should be contravariant with parameter $credentials (array) of method CodeIgniter\\Shield\\Authentication\\AuthenticatorInterface::attempt()',
7272
'identifier' => 'method.childParameterType',
7373
'count' => 1,
7474
'path' => __DIR__ . '/src/Authentication/Authenticators/JWT.php',
7575
];
7676
$ignoreErrors[] = [
77-
'rawMessage' => 'Parameter #1 $credentials (array{token?: string}) of method CodeIgniter\\Shield\\Authentication\\Authenticators\\JWT::check() should be contravariant with parameter $credentials (array) of method CodeIgniter\\Shield\\Authentication\\AuthenticatorInterface::check()',
77+
'rawMessage' => 'Parameter #1 $credentials (array{token?: string, ...}) of method CodeIgniter\\Shield\\Authentication\\Authenticators\\JWT::check() should be contravariant with parameter $credentials (array) of method CodeIgniter\\Shield\\Authentication\\AuthenticatorInterface::check()',
7878
'identifier' => 'method.childParameterType',
7979
'count' => 1,
8080
'path' => __DIR__ . '/src/Authentication/Authenticators/JWT.php',
@@ -110,13 +110,13 @@
110110
'path' => __DIR__ . '/src/Authentication/Authenticators/Session.php',
111111
];
112112
$ignoreErrors[] = [
113-
'rawMessage' => 'Parameter #1 $credentials (array{email?: string, username?: string, password?: string}) of method CodeIgniter\\Shield\\Authentication\\Authenticators\\Session::attempt() should be contravariant with parameter $credentials (array) of method CodeIgniter\\Shield\\Authentication\\AuthenticatorInterface::attempt()',
113+
'rawMessage' => 'Parameter #1 $credentials (array{email?: string, username?: string, password?: string, ...}) of method CodeIgniter\\Shield\\Authentication\\Authenticators\\Session::attempt() should be contravariant with parameter $credentials (array) of method CodeIgniter\\Shield\\Authentication\\AuthenticatorInterface::attempt()',
114114
'identifier' => 'method.childParameterType',
115115
'count' => 1,
116116
'path' => __DIR__ . '/src/Authentication/Authenticators/Session.php',
117117
];
118118
$ignoreErrors[] = [
119-
'rawMessage' => 'Parameter #1 $credentials (array{email?: string, username?: string, password?: string}) of method CodeIgniter\\Shield\\Authentication\\Authenticators\\Session::check() should be contravariant with parameter $credentials (array) of method CodeIgniter\\Shield\\Authentication\\AuthenticatorInterface::check()',
119+
'rawMessage' => 'Parameter #1 $credentials (array{email?: string, username?: string, password?: string, ...}) of method CodeIgniter\\Shield\\Authentication\\Authenticators\\Session::check() should be contravariant with parameter $credentials (array) of method CodeIgniter\\Shield\\Authentication\\AuthenticatorInterface::check()',
120120
'identifier' => 'method.childParameterType',
121121
'count' => 1,
122122
'path' => __DIR__ . '/src/Authentication/Authenticators/Session.php',

src/Auth.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
/**
2626
* Facade for Authentication
2727
*
28-
* @method Result attempt(array{email?: string, username?: string, password?: string, token?: string} $credentials)
29-
* @method Result check(array{email?: string, username?: string, password?: string, token?: string} $credentials)
30-
* @method bool checkAction(string $token, string $type) [Session]
31-
* @method void forget(?User $user = null) [Session]
28+
* @method Result attempt(array{email?: string, username?: string, password?: string, token?: string, ...} $credentials)
29+
* @method Result check(array{email?: string, username?: string, password?: string, token?: string, ...} $credentials)
30+
* @method bool checkAction(string $token, string $type) [Session]
31+
* @method void forget(?User $user = null) [Session]
3232
* @method User|null getUser()
3333
* @method bool loggedIn()
3434
* @method bool login(User $user)
3535
* @method void loginById($userId)
3636
* @method bool logout()
3737
* @method void recordActiveDate()
38-
* @method $this remember(bool $shouldRemember = true) [Session]
38+
* @method $this remember(bool $shouldRemember = true) [Session]
3939
*/
4040
class Auth
4141
{

src/Authentication/Authenticators/JWT.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct(
6464
* Attempts to authenticate a user with the given $credentials.
6565
* Logs the user in with a successful check.
6666
*
67-
* @param array{token?: string} $credentials
67+
* @param array{token?: string, ...} $credentials
6868
*/
6969
public function attempt(array $credentials): Result
7070
{
@@ -141,7 +141,7 @@ public function attempt(array $credentials): Result
141141
* In this case, $credentials has only a single valid value: token,
142142
* which is the plain text token to return.
143143
*
144-
* @param array{token?: string} $credentials
144+
* @param array{token?: string, ...} $credentials
145145
*/
146146
public function check(array $credentials): Result
147147
{

src/Authentication/Authenticators/Session.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function remember(bool $shouldRemember = true): self
122122
* Attempts to authenticate a user with the given $credentials.
123123
* Logs the user in with a successful check.
124124
*
125-
* @phpstan-param array{email?: string, username?: string, password?: string} $credentials
125+
* @phpstan-param array{email?: string, username?: string, password?: string, ...} $credentials
126126
*/
127127
public function attempt(array $credentials): Result
128128
{
@@ -315,7 +315,7 @@ private function recordLoginAttempt(
315315
* Checks a user's $credentials to see if they match an
316316
* existing user.
317317
*
318-
* @phpstan-param array{email?: string, username?: string, password?: string} $credentials
318+
* @phpstan-param array{email?: string, username?: string, password?: string, ...} $credentials
319319
*/
320320
public function check(array $credentials): Result
321321
{

0 commit comments

Comments
 (0)