Skip to content

Commit 96825d6

Browse files
authored
chore: fix code to comply with latest PHPStan, Rector and CS (#1268)
* fix cs * phpstan - ignore all errors related to internal symbols * phpstan - apply suggestions * phpstan - update baseline * rector - update config * rector - apply suggestions * cs - fix style by replacing FQCN with import
1 parent 81b69bf commit 96825d6

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

phpstan-baseline.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@
166166
'path' => __DIR__ . '/src/Collectors/Auth.php',
167167
];
168168
$ignoreErrors[] = [
169-
'message' => '#^Cannot access property \\$id on array\\<string, string\\>\\|object\\.$#',
169+
'message' => '#^Cannot access property \\$expires on array\\<string, string\\>\\|object\\.$#',
170170
'identifier' => 'property.nonObject',
171-
'count' => 9,
171+
'count' => 3,
172172
'path' => __DIR__ . '/src/Commands/Hmac.php',
173173
];
174174
$ignoreErrors[] = [
175-
'message' => '#^Cannot access property \\$expires on array\\<string, string\\>\\|object\\.$#',
175+
'message' => '#^Cannot access property \\$id on array\\<string, string\\>\\|object\\.$#',
176176
'identifier' => 'property.nonObject',
177-
'count' => 3,
177+
'count' => 9,
178178
'path' => __DIR__ . '/src/Commands/Hmac.php',
179179
];
180180
$ignoreErrors[] = [
@@ -492,6 +492,13 @@
492492
'count' => 6,
493493
'path' => __DIR__ . '/tests/Unit/Authentication/JWT/JWTManagerTest.php',
494494
];
495+
$ignoreErrors[] = [
496+
'message' => '#^Call to deprecated method __construct\\(\\) of class CodeIgniter\\\\HTTP\\\\Response\\:
497+
4\\.5\\.0 The param \\$config is no longer used\\.$#',
498+
'identifier' => 'method.deprecated',
499+
'count' => 3,
500+
'path' => __DIR__ . '/tests/Unit/PwnedValidatorTest.php',
501+
];
495502
$ignoreErrors[] = [
496503
'message' => '#^Call to an undefined method CodeIgniter\\\\Shield\\\\Models\\\\UserModel\\:\\:getLastQuery\\(\\)\\.$#',
497504
'identifier' => 'method.notFound',

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ parameters:
3434
disallowedImplicitArrayCreation: true
3535
disallowedShortTernary: true
3636
matchingInheritedMethodNames: true
37+
ignoreErrors:
38+
- identifier: function.internal
39+
- identifier: return.internalClass
40+
- identifier: staticMethod.internal

rector.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@
4444
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
4545
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
4646
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
47-
use Rector\Php81\Rector\ClassMethod\NewInInitializerRector;
4847
use Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\AnnotationWithValueToAttributeRector;
4948
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
50-
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector;
5149
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;
5250
use Rector\PHPUnit\Set\PHPUnitSetList;
5351
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
@@ -135,15 +133,7 @@
135133
__DIR__ . '/src/Commands/Setup.php',
136134
],
137135

138-
// Ignore for some existing classes to prevent BC break
139-
NewInInitializerRector::class => [
140-
__DIR__ . '/src/Authentication/JWT/JWSEncoder.php',
141-
__DIR__ . '/src/Authentication/JWT/JWSDecoder.php',
142-
__DIR__ . '/src/Authentication/JWTManager.php',
143-
],
144-
145136
// Ignore some PHPUnit rules
146-
AssertCountWithZeroToAssertEmptyRector::class,
147137
AssertEmptyNullableObjectToAssertInstanceofRector::class,
148138
]);
149139

src/Authentication/Authenticators/Session.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,9 @@ public function logout(): void
824824
/** @var \CodeIgniter\Session\Session $session */
825825
$session = session();
826826
$sessionData = $session->get();
827-
if (isset($sessionData)) {
828-
foreach (array_keys($sessionData) as $key) {
829-
$session->remove($key);
830-
}
827+
828+
foreach (array_keys($sessionData) as $key) {
829+
$session->remove($key);
831830
}
832831

833832
// Regenerate the session ID for a touch of added safety.

src/Views/email_2fa_show.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<?php
2+
3+
use CodeIgniter\Shield\Entities\User;
4+
5+
?>
6+
17
<?= $this->extend(config('Auth')->views['layout']) ?>
28

39
<?= $this->section('title') ?><?= lang('Auth.email2FATitle') ?> <?= $this->endSection() ?>
@@ -22,7 +28,7 @@
2228
<div class="mb-2">
2329
<input type="email" class="form-control" name="email"
2430
inputmode="email" autocomplete="email" placeholder="<?= lang('Auth.email') ?>"
25-
<?php /** @var CodeIgniter\Shield\Entities\User $user */ ?>
31+
<?php /** @var User $user */ ?>
2632
value="<?= old('email', $user->email) ?>" required>
2733
</div>
2834

tests/Commands/UserTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ public function testAddgroup(): void
592592

593593
$users = model(UserModel::class);
594594
$user = $users->findByCredentials(['email' => 'user10@example.com']);
595+
$this->assertInstanceOf(UserEntity::class, $user);
595596
$this->assertTrue($user->inGroup('admin'));
596597
}
597598

@@ -632,6 +633,7 @@ public function testAddgroupCancel(): void
632633

633634
$users = model(UserModel::class);
634635
$user = $users->findByCredentials(['email' => 'user10@example.com']);
636+
$this->assertInstanceOf(UserEntity::class, $user);
635637
$this->assertFalse($user->inGroup('admin'));
636638
}
637639

@@ -644,6 +646,7 @@ public function testRemovegroup(): void
644646
]);
645647
$users = model(UserModel::class);
646648
$user = $users->findByCredentials(['email' => 'user11@example.com']);
649+
$this->assertInstanceOf(UserEntity::class, $user);
647650
$user->addGroup('admin');
648651
$this->assertTrue($user->inGroup('admin'));
649652

@@ -658,6 +661,7 @@ public function testRemovegroup(): void
658661

659662
$users = model(UserModel::class);
660663
$user = $users->findByCredentials(['email' => 'user11@example.com']);
664+
$this->assertInstanceOf(UserEntity::class, $user);
661665
$this->assertFalse($user->inGroup('admin'));
662666
}
663667

@@ -670,6 +674,7 @@ public function testRemovegroupWithInvalidGroup(): void
670674
]);
671675
$users = model(UserModel::class);
672676
$user = $users->findByCredentials(['email' => 'user11@example.com']);
677+
$this->assertInstanceOf(UserEntity::class, $user);
673678
$user->addGroup('admin');
674679
$this->assertTrue($user->inGroup('admin'));
675680

@@ -684,6 +689,7 @@ public function testRemovegroupWithInvalidGroup(): void
684689

685690
$users = model(UserModel::class);
686691
$user = $users->findByCredentials(['email' => 'user11@example.com']);
692+
$this->assertInstanceOf(UserEntity::class, $user);
687693
$this->assertTrue($user->inGroup('admin'));
688694
}
689695

@@ -696,6 +702,7 @@ public function testRemovegroupCancel(): void
696702
]);
697703
$users = model(UserModel::class);
698704
$user = $users->findByCredentials(['email' => 'user11@example.com']);
705+
$this->assertInstanceOf(UserEntity::class, $user);
699706
$user->addGroup('admin');
700707
$this->assertTrue($user->inGroup('admin'));
701708

@@ -710,6 +717,7 @@ public function testRemovegroupCancel(): void
710717

711718
$users = model(UserModel::class);
712719
$user = $users->findByCredentials(['email' => 'user11@example.com']);
720+
$this->assertInstanceOf(UserEntity::class, $user);
713721
$this->assertTrue($user->inGroup('admin'));
714722
}
715723
}

tests/Unit/UserModelTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ public function testUpdateUserArrayWithUserDataToUpdate(): void
207207

208208
$user = $users->findByCredentials(['email' => 'foo@bar.com']);
209209

210+
$this->assertInstanceOf(User::class, $user);
211+
210212
$user->username = 'bar';
211213
$user->email = 'bar@bar.com';
212214
$user->active = true;

0 commit comments

Comments
 (0)