Skip to content

Commit 417cbd2

Browse files
authored
refactor: Fix phpstan errors related to Autoloader (#9249)
* refactor: Fix `phpstan` errors related to `Autoloader` * fix: Update @ignore-line * fix: Save `realpath()` as variable * refactor: `phpstan` strict comparison * fix: Restore check helpers
1 parent 42801e7 commit 417cbd2

15 files changed

+64
-222
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,12 @@
77
'count' => 1,
88
'path' => __DIR__ . '/app/Config/Filters.php',
99
];
10-
$ignoreErrors[] = [
11-
// identifier: function.alreadyNarrowedType
12-
'message' => '#^Call to function method_exists\\(\\) with \'Composer\\\\\\\\InstalledVersions\' and \'getAllRawData\' will always evaluate to true\\.$#',
13-
'count' => 1,
14-
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
15-
];
16-
$ignoreErrors[] = [
17-
// identifier: missingType.iterableValue
18-
'message' => '#^Method CodeIgniter\\\\Autoloader\\\\Autoloader\\:\\:loadComposerNamespaces\\(\\) has parameter \\$composerPackages with no value type specified in iterable type array\\.$#',
19-
'count' => 1,
20-
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
21-
];
2210
$ignoreErrors[] = [
2311
// identifier: isset.property
2412
'message' => '#^Property Config\\\\Autoload\\:\\:\\$helpers \\(array\\<int, string\\>\\) in isset\\(\\) is not nullable\\.$#',
2513
'count' => 1,
2614
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
2715
];
28-
$ignoreErrors[] = [
29-
// identifier: ternary.condNotBoolean
30-
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\|string given\\.$#',
31-
'count' => 1,
32-
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
33-
];
34-
$ignoreErrors[] = [
35-
// identifier: ternary.shortNotAllowed
36-
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
37-
'count' => 6,
38-
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
39-
];
40-
$ignoreErrors[] = [
41-
// identifier: missingType.iterableValue
42-
'message' => '#^Method CodeIgniter\\\\Autoloader\\\\FileLocatorCached\\:\\:search\\(\\) return type has no value type specified in iterable type array\\.$#',
43-
'count' => 1,
44-
'path' => __DIR__ . '/system/Autoloader/FileLocatorCached.php',
45-
];
46-
$ignoreErrors[] = [
47-
// identifier: missingType.iterableValue
48-
'message' => '#^Property CodeIgniter\\\\Autoloader\\\\FileLocatorCached\\:\\:\\$cache type has no value type specified in iterable type array\\.$#',
49-
'count' => 1,
50-
'path' => __DIR__ . '/system/Autoloader/FileLocatorCached.php',
51-
];
52-
$ignoreErrors[] = [
53-
// identifier: missingType.iterableValue
54-
'message' => '#^Method CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\:\\:search\\(\\) return type has no value type specified in iterable type array\\.$#',
55-
'count' => 1,
56-
'path' => __DIR__ . '/system/Autoloader/FileLocatorInterface.php',
57-
];
5816
$ignoreErrors[] = [
5917
// identifier: missingType.iterableValue
6018
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:__call\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#',
@@ -1021,12 +979,6 @@
1021979
'count' => 1,
1022980
'path' => __DIR__ . '/system/Common.php',
1023981
];
1024-
$ignoreErrors[] = [
1025-
// identifier: empty.notAllowed
1026-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
1027-
'count' => 4,
1028-
'path' => __DIR__ . '/system/Common.php',
1029-
];
1030982
$ignoreErrors[] = [
1031983
// identifier: missingType.iterableValue
1032984
'message' => '#^Function cache\\(\\) return type has no value type specified in iterable type array\\.$#',
@@ -1297,18 +1249,6 @@
12971249
'count' => 1,
12981250
'path' => __DIR__ . '/system/Config/Factories.php',
12991251
];
1300-
$ignoreErrors[] = [
1301-
// identifier: booleanNot.exprNotBoolean
1302-
'message' => '#^Only booleans are allowed in a negated boolean, array given\\.$#',
1303-
'count' => 1,
1304-
'path' => __DIR__ . '/system/Config/Factories.php',
1305-
];
1306-
$ignoreErrors[] = [
1307-
// identifier: booleanNot.exprNotBoolean
1308-
'message' => '#^Only booleans are allowed in a negated boolean, string\\|null given\\.$#',
1309-
'count' => 2,
1310-
'path' => __DIR__ . '/system/Config/Factories.php',
1311-
];
13121252
$ignoreErrors[] = [
13131253
// identifier: missingType.iterableValue
13141254
'message' => '#^Property CodeIgniter\\\\Config\\\\Factory\\:\\:\\$default type has no value type specified in iterable type array\\.$#',
@@ -9241,12 +9181,6 @@
92419181
'count' => 1,
92429182
'path' => __DIR__ . '/system/Test/CIUnitTestCase.php',
92439183
];
9244-
$ignoreErrors[] = [
9245-
// identifier: missingType.callable
9246-
'message' => '#^Method CodeIgniter\\\\Test\\\\CIUnitTestCase\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
9247-
'count' => 1,
9248-
'path' => __DIR__ . '/system/Test/CIUnitTestCase.php',
9249-
];
92509184
$ignoreErrors[] = [
92519185
// identifier: missingType.return
92529186
'message' => '#^Method CodeIgniter\\\\Test\\\\CIUnitTestCase\\:\\:mockCache\\(\\) has no return type specified\\.$#',
@@ -9277,12 +9211,6 @@
92779211
'count' => 1,
92789212
'path' => __DIR__ . '/system/Test/CIUnitTestCase.php',
92799213
];
9280-
$ignoreErrors[] = [
9281-
// identifier: missingType.return
9282-
'message' => '#^Method CodeIgniter\\\\Test\\\\CIUnitTestCase\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
9283-
'count' => 1,
9284-
'path' => __DIR__ . '/system/Test/CIUnitTestCase.php',
9285-
];
92869214
$ignoreErrors[] = [
92879215
// identifier: booleanNot.exprNotBoolean
92889216
'message' => '#^Only booleans are allowed in a negated boolean, CodeIgniter\\\\CodeIgniter given\\.$#',
@@ -11821,36 +11749,6 @@
1182111749
'count' => 1,
1182211750
'path' => __DIR__ . '/tests/system/AutoReview/FrameworkCodeTest.php',
1182311751
];
11824-
$ignoreErrors[] = [
11825-
// identifier: missingType.callable
11826-
'message' => '#^Method CodeIgniter\\\\Autoloader\\\\AutoloaderTest\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
11827-
'count' => 1,
11828-
'path' => __DIR__ . '/tests/system/Autoloader/AutoloaderTest.php',
11829-
];
11830-
$ignoreErrors[] = [
11831-
// identifier: missingType.return
11832-
'message' => '#^Method CodeIgniter\\\\Autoloader\\\\AutoloaderTest\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
11833-
'count' => 1,
11834-
'path' => __DIR__ . '/tests/system/Autoloader/AutoloaderTest.php',
11835-
];
11836-
$ignoreErrors[] = [
11837-
// identifier: ternary.shortNotAllowed
11838-
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
11839-
'count' => 2,
11840-
'path' => __DIR__ . '/tests/system/Autoloader/AutoloaderTest.php',
11841-
];
11842-
$ignoreErrors[] = [
11843-
// identifier: method.notFound
11844-
'message' => '#^Call to an undefined method CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\:\\:__destruct\\(\\)\\.$#',
11845-
'count' => 1,
11846-
'path' => __DIR__ . '/tests/system/Autoloader/FileLocatorCachedTest.php',
11847-
];
11848-
$ignoreErrors[] = [
11849-
// identifier: method.notFound
11850-
'message' => '#^Call to an undefined method CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\:\\:deleteCache\\(\\)\\.$#',
11851-
'count' => 1,
11852-
'path' => __DIR__ . '/tests/system/Autoloader/FileLocatorCachedTest.php',
11853-
];
1185411752
$ignoreErrors[] = [
1185511753
// identifier: codeigniter.superglobalAccessAssign
1185611754
'message' => '#^Assigning 3 directly on offset \'argc\' of \\$_SERVER is discouraged\\.$#',
@@ -13141,24 +13039,12 @@
1314113039
'count' => 1,
1314213040
'path' => __DIR__ . '/tests/system/Database/Builder/WhereTest.php',
1314313041
];
13144-
$ignoreErrors[] = [
13145-
// identifier: missingType.callable
13146-
'message' => '#^Method CodeIgniter\\\\Database\\\\ConfigTest\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
13147-
'count' => 1,
13148-
'path' => __DIR__ . '/tests/system/Database/ConfigTest.php',
13149-
];
1315013042
$ignoreErrors[] = [
1315113043
// identifier: missingType.iterableValue
1315213044
'message' => '#^Method CodeIgniter\\\\Database\\\\ConfigTest\\:\\:provideConvertDSN\\(\\) return type has no value type specified in iterable type iterable\\.$#',
1315313045
'count' => 1,
1315413046
'path' => __DIR__ . '/tests/system/Database/ConfigTest.php',
1315513047
];
13156-
$ignoreErrors[] = [
13157-
// identifier: missingType.return
13158-
'message' => '#^Method CodeIgniter\\\\Database\\\\ConfigTest\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
13159-
'count' => 1,
13160-
'path' => __DIR__ . '/tests/system/Database/ConfigTest.php',
13161-
];
1316213048
$ignoreErrors[] = [
1316313049
// identifier: missingType.iterableValue
1316413050
'message' => '#^Property CodeIgniter\\\\Database\\\\ConfigTest\\:\\:\\$dsnGroup type has no value type specified in iterable type array\\.$#',
@@ -13501,18 +13387,6 @@
1350113387
'count' => 1,
1350213388
'path' => __DIR__ . '/tests/system/Debug/ExceptionsTest.php',
1350313389
];
13504-
$ignoreErrors[] = [
13505-
// identifier: missingType.callable
13506-
'message' => '#^Method CodeIgniter\\\\Debug\\\\ExceptionsTest\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
13507-
'count' => 1,
13508-
'path' => __DIR__ . '/tests/system/Debug/ExceptionsTest.php',
13509-
];
13510-
$ignoreErrors[] = [
13511-
// identifier: missingType.return
13512-
'message' => '#^Method CodeIgniter\\\\Debug\\\\ExceptionsTest\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
13513-
'count' => 1,
13514-
'path' => __DIR__ . '/tests/system/Debug/ExceptionsTest.php',
13515-
];
1351613390
$ignoreErrors[] = [
1351713391
// identifier: argument.type
1351813392
'message' => '#^Parameter \\#2 \\$callable of method CodeIgniter\\\\Debug\\\\Timer\\:\\:record\\(\\) expects callable\\(\\)\\: mixed, \'strlen\' given\\.$#',
@@ -13651,12 +13525,6 @@
1365113525
'count' => 1,
1365213526
'path' => __DIR__ . '/tests/system/Entity/EntityTest.php',
1365313527
];
13654-
$ignoreErrors[] = [
13655-
// identifier: missingType.callable
13656-
'message' => '#^Method CodeIgniter\\\\Entity\\\\EntityTest\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
13657-
'count' => 1,
13658-
'path' => __DIR__ . '/tests/system/Entity/EntityTest.php',
13659-
];
1366013528
$ignoreErrors[] = [
1366113529
// identifier: missingType.return
1366213530
'message' => '#^Method CodeIgniter\\\\Entity\\\\EntityTest\\:\\:getSimpleSwappedEntity\\(\\) has no return type specified\\.$#',
@@ -13669,12 +13537,6 @@
1366913537
'count' => 1,
1367013538
'path' => __DIR__ . '/tests/system/Entity/EntityTest.php',
1367113539
];
13672-
$ignoreErrors[] = [
13673-
// identifier: missingType.return
13674-
'message' => '#^Method CodeIgniter\\\\Entity\\\\EntityTest\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
13675-
'count' => 1,
13676-
'path' => __DIR__ . '/tests/system/Entity/EntityTest.php',
13677-
];
1367813540
$ignoreErrors[] = [
1367913541
// identifier: codeigniter.configArgumentInstanceof
1368013542
'message' => '#^Argument \\#1 \\$name \\(\'Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
@@ -15979,18 +15841,6 @@
1597915841
'count' => 1,
1598015842
'path' => __DIR__ . '/tests/system/Models/InsertModelTest.php',
1598115843
];
15982-
$ignoreErrors[] = [
15983-
// identifier: missingType.callable
15984-
'message' => '#^Method CodeIgniter\\\\Models\\\\LiveModelTestCase\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
15985-
'count' => 1,
15986-
'path' => __DIR__ . '/tests/system/Models/LiveModelTestCase.php',
15987-
];
15988-
$ignoreErrors[] = [
15989-
// identifier: missingType.return
15990-
'message' => '#^Method CodeIgniter\\\\Models\\\\LiveModelTestCase\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
15991-
'count' => 1,
15992-
'path' => __DIR__ . '/tests/system/Models/LiveModelTestCase.php',
15993-
];
1599415844
$ignoreErrors[] = [
1599515845
// identifier: property.nonObject
1599615846
'message' => '#^Cannot access property \\$created_at on array\\.$#',
@@ -17041,18 +16891,6 @@
1704116891
'count' => 1,
1704216892
'path' => __DIR__ . '/tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php',
1704316893
];
17044-
$ignoreErrors[] = [
17045-
// identifier: missingType.callable
17046-
'message' => '#^Method CodeIgniter\\\\Session\\\\Handlers\\\\Database\\\\AbstractHandlerTestCase\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
17047-
'count' => 1,
17048-
'path' => __DIR__ . '/tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php',
17049-
];
17050-
$ignoreErrors[] = [
17051-
// identifier: missingType.return
17052-
'message' => '#^Method CodeIgniter\\\\Session\\\\Handlers\\\\Database\\\\AbstractHandlerTestCase\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
17053-
'count' => 1,
17054-
'path' => __DIR__ . '/tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php',
17055-
];
1705616894
$ignoreErrors[] = [
1705716895
// identifier: missingType.return
1705816896
'message' => '#^Method CodeIgniter\\\\Session\\\\Handlers\\\\Database\\\\MySQLiHandlerTest\\:\\:getInstance\\(\\) has no return type specified\\.$#',
@@ -18325,18 +18163,6 @@
1832518163
'count' => 1,
1832618164
'path' => __DIR__ . '/tests/system/Validation/ValidationTest.php',
1832718165
];
18328-
$ignoreErrors[] = [
18329-
// identifier: assign.propertyType
18330-
'message' => '#^Property CodeIgniter\\\\View\\\\DecoratorsTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
18331-
'count' => 1,
18332-
'path' => __DIR__ . '/tests/system/View/DecoratorsTest.php',
18333-
];
18334-
$ignoreErrors[] = [
18335-
// identifier: assign.propertyType
18336-
'message' => '#^Property CodeIgniter\\\\View\\\\ParserFilterTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
18337-
'count' => 1,
18338-
'path' => __DIR__ . '/tests/system/View/ParserFilterTest.php',
18339-
];
1834018166
$ignoreErrors[] = [
1834118167
// identifier: missingType.return
1834218168
'message' => '#^Method CodeIgniter\\\\View\\\\ParserPluginTest\\:\\:setHints\\(\\) has no return type specified\\.$#',
@@ -18367,12 +18193,6 @@
1836718193
'count' => 3,
1836818194
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
1836918195
];
18370-
$ignoreErrors[] = [
18371-
// identifier: assign.propertyType
18372-
'message' => '#^Property CodeIgniter\\\\View\\\\ParserTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
18373-
'count' => 1,
18374-
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
18375-
];
1837618196
$ignoreErrors[] = [
1837718197
// identifier: method.notFound
1837818198
'message' => '#^Call to an undefined method CodeIgniter\\\\View\\\\Table\\:\\:compileTemplate\\(\\)\\.$#',
@@ -18463,11 +18283,5 @@
1846318283
'count' => 1,
1846418284
'path' => __DIR__ . '/tests/system/View/TableTest.php',
1846518285
];
18466-
$ignoreErrors[] = [
18467-
// identifier: assign.propertyType
18468-
'message' => '#^Property CodeIgniter\\\\View\\\\ViewTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
18469-
'count' => 1,
18470-
'path' => __DIR__ . '/tests/system/View/ViewTest.php',
18471-
];
1847218286

1847318287
return ['parameters' => ['ignoreErrors' => $ignoreErrors]];

system/Autoloader/Autoloader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ public function sanitizeFilename(string $filename): string
366366
return $cleanFilename;
367367
}
368368

369+
/**
370+
* @param array{only?: list<string>, exclude?: list<string>} $composerPackages
371+
*/
369372
private function loadComposerNamespaces(ClassLoader $composer, array $composerPackages): void
370373
{
371374
$namespacePaths = $composer->getPrefixesPsr4();
@@ -379,7 +382,7 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa
379382
}
380383
}
381384

382-
if (! method_exists(InstalledVersions::class, 'getAllRawData')) {
385+
if (! method_exists(InstalledVersions::class, 'getAllRawData')) { // @phpstan-ignore function.alreadyNarrowedType
383386
throw new RuntimeException(
384387
'Your Composer version is too old.'
385388
. ' Please update Composer (run `composer self-update`) to v2.0.14 or later'

0 commit comments

Comments
 (0)