Skip to content

Commit 84c11f4

Browse files
committed
refactor: Fix phpstan errors related to Autoloader
1 parent 65872e5 commit 84c11f4

14 files changed

+52
-240
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,6 @@
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-
];
22-
$ignoreErrors[] = [
23-
// identifier: isset.property
24-
'message' => '#^Property Config\\\\Autoload\\:\\:\\$helpers \\(array\\<int, string\\>\\) in isset\\(\\) is not nullable\\.$#',
25-
'count' => 1,
26-
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
27-
];
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-
];
5810
$ignoreErrors[] = [
5911
// identifier: missingType.iterableValue
6012
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:__call\\(\\) has parameter \\$params with 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\\.$#',
@@ -17047,18 +16897,6 @@
1704716897
'count' => 1,
1704816898
'path' => __DIR__ . '/tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php',
1704916899
];
17050-
$ignoreErrors[] = [
17051-
// identifier: missingType.callable
17052-
'message' => '#^Method CodeIgniter\\\\Session\\\\Handlers\\\\Database\\\\AbstractHandlerTestCase\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
17053-
'count' => 1,
17054-
'path' => __DIR__ . '/tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php',
17055-
];
17056-
$ignoreErrors[] = [
17057-
// identifier: missingType.return
17058-
'message' => '#^Method CodeIgniter\\\\Session\\\\Handlers\\\\Database\\\\AbstractHandlerTestCase\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
17059-
'count' => 1,
17060-
'path' => __DIR__ . '/tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php',
17061-
];
1706216900
$ignoreErrors[] = [
1706316901
// identifier: missingType.return
1706416902
'message' => '#^Method CodeIgniter\\\\Session\\\\Handlers\\\\Database\\\\MySQLiHandlerTest\\:\\:getInstance\\(\\) has no return type specified\\.$#',
@@ -18331,18 +18169,6 @@
1833118169
'count' => 1,
1833218170
'path' => __DIR__ . '/tests/system/Validation/ValidationTest.php',
1833318171
];
18334-
$ignoreErrors[] = [
18335-
// identifier: assign.propertyType
18336-
'message' => '#^Property CodeIgniter\\\\View\\\\DecoratorsTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
18337-
'count' => 1,
18338-
'path' => __DIR__ . '/tests/system/View/DecoratorsTest.php',
18339-
];
18340-
$ignoreErrors[] = [
18341-
// identifier: assign.propertyType
18342-
'message' => '#^Property CodeIgniter\\\\View\\\\ParserFilterTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
18343-
'count' => 1,
18344-
'path' => __DIR__ . '/tests/system/View/ParserFilterTest.php',
18345-
];
1834618172
$ignoreErrors[] = [
1834718173
// identifier: missingType.return
1834818174
'message' => '#^Method CodeIgniter\\\\View\\\\ParserPluginTest\\:\\:setHints\\(\\) has no return type specified\\.$#',
@@ -18367,36 +18193,12 @@
1836718193
'count' => 1,
1836818194
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
1836918195
];
18370-
$ignoreErrors[] = [
18371-
// identifier: missingType.iterableValue
18372-
'message' => '#^Method class@anonymous/tests/system/View/ParserTest\\.php\\:340\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#',
18373-
'count' => 1,
18374-
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
18375-
];
1837618196
$ignoreErrors[] = [
1837718197
// identifier: argument.type
1837818198
'message' => '#^Parameter \\#2 \\$context of method CodeIgniter\\\\View\\\\Parser\\:\\:setData\\(\\) expects \'attr\'\\|\'css\'\\|\'html\'\\|\'js\'\\|\'raw\'\\|\'url\'\\|null, \'unknown\' given\\.$#',
1837918199
'count' => 3,
1838018200
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
1838118201
];
18382-
$ignoreErrors[] = [
18383-
// identifier: assign.propertyType
18384-
'message' => '#^Property CodeIgniter\\\\View\\\\ParserTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
18385-
'count' => 1,
18386-
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
18387-
];
18388-
$ignoreErrors[] = [
18389-
// identifier: missingType.property
18390-
'message' => '#^Property class@anonymous/tests/system/View/ParserTest\\.php\\:340\\:\\:\\$bar has no type specified\\.$#',
18391-
'count' => 1,
18392-
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
18393-
];
18394-
$ignoreErrors[] = [
18395-
// identifier: missingType.property
18396-
'message' => '#^Property class@anonymous/tests/system/View/ParserTest\\.php\\:340\\:\\:\\$foo has no type specified\\.$#',
18397-
'count' => 1,
18398-
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
18399-
];
1840018202
$ignoreErrors[] = [
1840118203
// identifier: method.notFound
1840218204
'message' => '#^Call to an undefined method CodeIgniter\\\\View\\\\Table\\:\\:compileTemplate\\(\\)\\.$#',
@@ -18487,11 +18289,5 @@
1848718289
'count' => 1,
1848818290
'path' => __DIR__ . '/tests/system/View/TableTest.php',
1848918291
];
18490-
$ignoreErrors[] = [
18491-
// identifier: assign.propertyType
18492-
'message' => '#^Property CodeIgniter\\\\View\\\\ViewTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
18493-
'count' => 1,
18494-
'path' => __DIR__ . '/tests/system/View/ViewTest.php',
18495-
];
1849618292

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

system/Autoloader/Autoloader.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function initialize(Autoload $config, Modules $modules)
124124
$this->files = $config->files;
125125
}
126126

127-
if (isset($config->helpers)) {
127+
if ($config->helpers !== []) {
128128
$this->helpers = [...$this->helpers, ...$config->helpers];
129129
}
130130

@@ -367,6 +367,9 @@ public function sanitizeFilename(string $filename): string
367367
return $cleanFilename;
368368
}
369369

370+
/**
371+
* @param array{only?: list<string>, exclude?: list<string>} $composerPackages
372+
*/
370373
private function loadComposerNamespaces(ClassLoader $composer, array $composerPackages): void
371374
{
372375
$namespacePaths = $composer->getPrefixesPsr4();
@@ -380,6 +383,7 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa
380383
}
381384
}
382385

386+
// @phpstan-ignore-next-line
383387
if (! method_exists(InstalledVersions::class, 'getAllRawData')) {
384388
throw new RuntimeException(
385389
'Your Composer version is too old.'

0 commit comments

Comments
 (0)