Skip to content

Commit 7e35a0c

Browse files
committed
fix PHPStan and apply Rector rules
1 parent e1d1994 commit 7e35a0c

5 files changed

Lines changed: 23 additions & 41 deletions

File tree

phpstan-baseline.php

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<?php declare(strict_types = 1);
22

33
$ignoreErrors = [];
4-
$ignoreErrors[] = [
5-
'rawMessage' => 'Call to deprecated function random_string():
6-
The type \'basic\', \'md5\', and \'sha1\' are deprecated. They are not cryptographically secure.',
7-
'identifier' => 'function.deprecated',
8-
'count' => 1,
9-
'path' => __DIR__ . '/src/Authentication/Actions/Email2FA.php',
10-
];
114
$ignoreErrors[] = [
125
'rawMessage' => 'Call to function model with CodeIgniter\\Shield\\Models\\UserIdentityModel::class is discouraged.',
136
'identifier' => 'codeigniter.factoriesClassConstFetch',
@@ -20,13 +13,6 @@
2013
'count' => 1,
2114
'path' => __DIR__ . '/src/Authentication/Actions/Email2FA.php',
2215
];
23-
$ignoreErrors[] = [
24-
'rawMessage' => 'Call to deprecated function random_string():
25-
The type \'basic\', \'md5\', and \'sha1\' are deprecated. They are not cryptographically secure.',
26-
'identifier' => 'function.deprecated',
27-
'count' => 1,
28-
'path' => __DIR__ . '/src/Authentication/Actions/EmailActivator.php',
29-
];
3016
$ignoreErrors[] = [
3117
'rawMessage' => 'Call to function model with CodeIgniter\\Shield\\Models\\UserIdentityModel::class is discouraged.',
3218
'identifier' => 'codeigniter.factoriesClassConstFetch',
@@ -195,13 +181,6 @@
195181
'count' => 9,
196182
'path' => __DIR__ . '/src/Commands/User.php',
197183
];
198-
$ignoreErrors[] = [
199-
'rawMessage' => 'Call to deprecated function random_string():
200-
The type \'basic\', \'md5\', and \'sha1\' are deprecated. They are not cryptographically secure.',
201-
'identifier' => 'function.deprecated',
202-
'count' => 1,
203-
'path' => __DIR__ . '/src/Controllers/MagicLinkController.php',
204-
];
205184
$ignoreErrors[] = [
206185
'rawMessage' => 'Call to function model with CodeIgniter\\Shield\\Models\\LoginModel::class is discouraged.',
207186
'identifier' => 'codeigniter.factoriesClassConstFetch',
@@ -388,20 +367,6 @@
388367
'count' => 1,
389368
'path' => __DIR__ . '/src/Filters/TokenAuth.php',
390369
];
391-
$ignoreErrors[] = [
392-
'rawMessage' => 'Call to deprecated function random_string():
393-
The type \'basic\', \'md5\', and \'sha1\' are deprecated. They are not cryptographically secure.',
394-
'identifier' => 'function.deprecated',
395-
'count' => 1,
396-
'path' => __DIR__ . '/src/Models/TokenLoginModel.php',
397-
];
398-
$ignoreErrors[] = [
399-
'rawMessage' => 'Call to deprecated function random_string():
400-
The type \'basic\', \'md5\', and \'sha1\' are deprecated. They are not cryptographically secure.',
401-
'identifier' => 'function.deprecated',
402-
'count' => 1,
403-
'path' => __DIR__ . '/src/Models/UserIdentityModel.php',
404-
];
405370
$ignoreErrors[] = [
406371
'rawMessage' => 'Call to function model with CodeIgniter\\Shield\\Models\\GroupModel::class is discouraged.',
407372
'identifier' => 'codeigniter.factoriesClassConstFetch',
@@ -462,6 +427,18 @@
462427
'count' => 8,
463428
'path' => __DIR__ . '/tests/Authentication/Authenticators/SessionAuthenticatorTest.php',
464429
];
430+
$ignoreErrors[] = [
431+
'rawMessage' => 'Parameter #1 $headers of method Tests\\Authentication\\Filters\\AbstractFilterTestCase::withHeaders() expects array<string, CodeIgniter\\HTTP\\Header|list<CodeIgniter\\HTTP\\Header>>, array{Authorization: non-falsy-string} given.',
432+
'identifier' => 'argument.type',
433+
'count' => 7,
434+
'path' => __DIR__ . '/tests/Authentication/Filters/HmacFilterTest.php',
435+
];
436+
$ignoreErrors[] = [
437+
'rawMessage' => 'Parameter #1 $headers of method Tests\\Authentication\\Filters\\JWTFilterTest::withHeaders() expects array<string, CodeIgniter\\HTTP\\Header|list<CodeIgniter\\HTTP\\Header>>, array{Authorization: non-falsy-string} given.',
438+
'identifier' => 'argument.type',
439+
'count' => 1,
440+
'path' => __DIR__ . '/tests/Authentication/Filters/JWTFilterTest.php',
441+
];
465442
$ignoreErrors[] = [
466443
'rawMessage' => 'Implicit array creation is not allowed - variable $users might not exist.',
467444
'identifier' => 'variable.implicitArray',

src/Authentication/Passwords/PwnedValidator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public function check(string $password, ?User $user = null): Result
4444
{
4545
$hashedPword = strtoupper(sha1($password));
4646
$rangeHash = substr($hashedPword, 0, 5);
47-
/** @var string $searchHash */
48-
$searchHash = substr($hashedPword, 5);
47+
$searchHash = substr($hashedPword, 5);
4948

5049
try {
5150
$client = Services::curlrequest([

src/Models/UserIdentityModel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace CodeIgniter\Shield\Models;
1515

16+
use CodeIgniter\Database\RawSql;
1617
use CodeIgniter\I18n\Time;
1718
use CodeIgniter\Shield\Authentication\Authenticators\AccessTokens;
1819
use CodeIgniter\Shield\Authentication\Authenticators\HmacSha256;
@@ -567,8 +568,8 @@ public function forceGlobalPasswordReset(): void
567568
* Override the Model's `update()` method.
568569
* Throws an Exception when it fails.
569570
*
570-
* @param array|int|string|null $id
571-
* @param array|object|null $row
571+
* @param int|list<int|string>|RawSql|string|null $id
572+
* @param array|object|null $row
572573
*
573574
* @return true if the update is successful
574575
*

src/Models/UserModel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace CodeIgniter\Shield\Models;
1515

1616
use CodeIgniter\Database\Exceptions\DataException;
17+
use CodeIgniter\Database\RawSql;
1718
use CodeIgniter\I18n\Time;
1819
use CodeIgniter\Shield\Authentication\Authenticators\Session;
1920
use CodeIgniter\Shield\Entities\User;
@@ -416,8 +417,8 @@ public function insert($row = null, bool $returnID = true)
416417
* Override the BaseModel's `update()` method.
417418
* If you pass User object, also updates Email Identity.
418419
*
419-
* @param array|int|string|null $id
420-
* @param array|User $row
420+
* @param int|list<int|string>|RawSql|string|null $id
421+
* @param array|User $row
421422
*
422423
* @return true if the update is successful
423424
*

tests/Unit/UserModelTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public function testSaveUpdateUserObjectWithUserDataToUpdate(): void
154154
$user->username = 'bar';
155155
$user->email = 'bar@bar.com';
156156
$user->active = true;
157+
$this->assertInstanceOf(User::class, $user);
157158

158159
$users->save($user);
159160

@@ -178,6 +179,7 @@ public function testUpdateUserObjectWithUserDataToUpdate(): void
178179
$user->username = 'bar';
179180
$user->email = 'bar@bar.com';
180181
$user->active = true;
182+
$this->assertInstanceOf(User::class, $user);
181183

182184
$users->update($user->id, $user);
183185

@@ -238,6 +240,7 @@ public function testSaveUpdateUserObjectWithoutUserDataToUpdate(): void
238240
$user = $users->findByCredentials(['email' => 'foo@bar.com']);
239241

240242
$user->email = 'bar@bar.com';
243+
$this->assertInstanceOf(User::class, $user);
241244

242245
$users->save($user);
243246

@@ -256,6 +259,7 @@ public function testUpdateUserObjectWithoutUserDataToUpdate(): void
256259
$user = $users->findByCredentials(['email' => 'foo@bar.com']);
257260

258261
$user->email = 'bar@bar.com';
262+
$this->assertInstanceOf(User::class, $user);
259263

260264
$users->update(null, $user);
261265

0 commit comments

Comments
 (0)