Skip to content

refactor: Fix phpstan errors related to Autoloader #9249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 0 additions & 186 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,12 @@
'count' => 1,
'path' => __DIR__ . '/app/Config/Filters.php',
];
$ignoreErrors[] = [
// identifier: function.alreadyNarrowedType
'message' => '#^Call to function method_exists\\(\\) with \'Composer\\\\\\\\InstalledVersions\' and \'getAllRawData\' will always evaluate to true\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Autoloader\\\\Autoloader\\:\\:loadComposerNamespaces\\(\\) has parameter \\$composerPackages with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
];
$ignoreErrors[] = [
// identifier: isset.property
'message' => '#^Property Config\\\\Autoload\\:\\:\\$helpers \\(array\\<int, string\\>\\) in isset\\(\\) is not nullable\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
];
$ignoreErrors[] = [
// identifier: ternary.condNotBoolean
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\|string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
];
$ignoreErrors[] = [
// identifier: ternary.shortNotAllowed
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
'count' => 6,
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Autoloader\\\\FileLocatorCached\\:\\:search\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/FileLocatorCached.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Property CodeIgniter\\\\Autoloader\\\\FileLocatorCached\\:\\:\\$cache type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/FileLocatorCached.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\:\\:search\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/FileLocatorInterface.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:__call\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -1021,12 +979,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Common.php',
];
$ignoreErrors[] = [
// identifier: empty.notAllowed
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 4,
'path' => __DIR__ . '/system/Common.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Function cache\\(\\) return type has no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -1297,18 +1249,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Config/Factories.php',
];
$ignoreErrors[] = [
// identifier: booleanNot.exprNotBoolean
'message' => '#^Only booleans are allowed in a negated boolean, array given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Config/Factories.php',
];
$ignoreErrors[] = [
// identifier: booleanNot.exprNotBoolean
'message' => '#^Only booleans are allowed in a negated boolean, string\\|null given\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/Config/Factories.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Property CodeIgniter\\\\Config\\\\Factory\\:\\:\\$default type has no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -9241,12 +9181,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Test/CIUnitTestCase.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Test\\\\CIUnitTestCase\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/CIUnitTestCase.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Test\\\\CIUnitTestCase\\:\\:mockCache\\(\\) has no return type specified\\.$#',
Expand Down Expand Up @@ -9277,12 +9211,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Test/CIUnitTestCase.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Test\\\\CIUnitTestCase\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/CIUnitTestCase.php',
];
$ignoreErrors[] = [
// identifier: booleanNot.exprNotBoolean
'message' => '#^Only booleans are allowed in a negated boolean, CodeIgniter\\\\CodeIgniter given\\.$#',
Expand Down Expand Up @@ -11821,36 +11749,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/AutoReview/FrameworkCodeTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Autoloader\\\\AutoloaderTest\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Autoloader/AutoloaderTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Autoloader\\\\AutoloaderTest\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Autoloader/AutoloaderTest.php',
];
$ignoreErrors[] = [
// identifier: ternary.shortNotAllowed
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
'count' => 2,
'path' => __DIR__ . '/tests/system/Autoloader/AutoloaderTest.php',
];
$ignoreErrors[] = [
// identifier: method.notFound
'message' => '#^Call to an undefined method CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\:\\:__destruct\\(\\)\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Autoloader/FileLocatorCachedTest.php',
];
$ignoreErrors[] = [
// identifier: method.notFound
'message' => '#^Call to an undefined method CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\:\\:deleteCache\\(\\)\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Autoloader/FileLocatorCachedTest.php',
];
$ignoreErrors[] = [
// identifier: codeigniter.superglobalAccessAssign
'message' => '#^Assigning 3 directly on offset \'argc\' of \\$_SERVER is discouraged\\.$#',
Expand Down Expand Up @@ -13141,24 +13039,12 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/Database/Builder/WhereTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\ConfigTest\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Database/ConfigTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\ConfigTest\\:\\:provideConvertDSN\\(\\) return type has no value type specified in iterable type iterable\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Database/ConfigTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Database\\\\ConfigTest\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Database/ConfigTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Property CodeIgniter\\\\Database\\\\ConfigTest\\:\\:\\$dsnGroup type has no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -13501,18 +13387,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/Debug/ExceptionsTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Debug\\\\ExceptionsTest\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Debug/ExceptionsTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Debug\\\\ExceptionsTest\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Debug/ExceptionsTest.php',
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#2 \\$callable of method CodeIgniter\\\\Debug\\\\Timer\\:\\:record\\(\\) expects callable\\(\\)\\: mixed, \'strlen\' given\\.$#',
Expand Down Expand Up @@ -13651,12 +13525,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/Entity/EntityTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Entity\\\\EntityTest\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Entity/EntityTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Entity\\\\EntityTest\\:\\:getSimpleSwappedEntity\\(\\) has no return type specified\\.$#',
Expand All @@ -13669,12 +13537,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/Entity/EntityTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Entity\\\\EntityTest\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Entity/EntityTest.php',
];
$ignoreErrors[] = [
// identifier: codeigniter.configArgumentInstanceof
'message' => '#^Argument \\#1 \\$name \\(\'Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
Expand Down Expand Up @@ -15979,18 +15841,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/Models/InsertModelTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Models\\\\LiveModelTestCase\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Models/LiveModelTestCase.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Models\\\\LiveModelTestCase\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Models/LiveModelTestCase.php',
];
$ignoreErrors[] = [
// identifier: property.nonObject
'message' => '#^Cannot access property \\$created_at on array\\.$#',
Expand Down Expand Up @@ -17041,18 +16891,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Session\\\\Handlers\\\\Database\\\\AbstractHandlerTestCase\\:\\:getPrivateMethodInvoker\\(\\) return type has no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Session\\\\Handlers\\\\Database\\\\AbstractHandlerTestCase\\:\\:setPrivateProperty\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Session\\\\Handlers\\\\Database\\\\MySQLiHandlerTest\\:\\:getInstance\\(\\) has no return type specified\\.$#',
Expand Down Expand Up @@ -18325,18 +18163,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/Validation/ValidationTest.php',
];
$ignoreErrors[] = [
// identifier: assign.propertyType
'message' => '#^Property CodeIgniter\\\\View\\\\DecoratorsTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/View/DecoratorsTest.php',
];
$ignoreErrors[] = [
// identifier: assign.propertyType
'message' => '#^Property CodeIgniter\\\\View\\\\ParserFilterTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/View/ParserFilterTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\View\\\\ParserPluginTest\\:\\:setHints\\(\\) has no return type specified\\.$#',
Expand Down Expand Up @@ -18367,12 +18193,6 @@
'count' => 3,
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
];
$ignoreErrors[] = [
// identifier: assign.propertyType
'message' => '#^Property CodeIgniter\\\\View\\\\ParserTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
];
$ignoreErrors[] = [
// identifier: method.notFound
'message' => '#^Call to an undefined method CodeIgniter\\\\View\\\\Table\\:\\:compileTemplate\\(\\)\\.$#',
Expand Down Expand Up @@ -18463,11 +18283,5 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/View/TableTest.php',
];
$ignoreErrors[] = [
// identifier: assign.propertyType
'message' => '#^Property CodeIgniter\\\\View\\\\ViewTest\\:\\:\\$loader \\(CodeIgniter\\\\Autoloader\\\\FileLocator\\) does not accept CodeIgniter\\\\Autoloader\\\\FileLocatorInterface\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/View/ViewTest.php',
];

return ['parameters' => ['ignoreErrors' => $ignoreErrors]];
5 changes: 4 additions & 1 deletion system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ public function sanitizeFilename(string $filename): string
return $cleanFilename;
}

/**
* @param array{only?: list<string>, exclude?: list<string>} $composerPackages
*/
private function loadComposerNamespaces(ClassLoader $composer, array $composerPackages): void
{
$namespacePaths = $composer->getPrefixesPsr4();
Expand All @@ -379,7 +382,7 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa
}
}

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