diff --git a/system/Commands/ListCommands.php b/system/Commands/ListCommands.php index 8761e2bb7bbc..c976733b768d 100644 --- a/system/Commands/ListCommands.php +++ b/system/Commands/ListCommands.php @@ -15,12 +15,15 @@ use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; +use CodeIgniter\CLI\Commands; /** * CI Help command for the spark script. * * Lists the basic usage information for the spark script, * and provides a way to list help for other commands. + * + * @phpstan-import-type commands_list from Commands */ class ListCommands extends BaseCommand { @@ -88,6 +91,8 @@ public function run(array $params) /** * Lists the commands with accompanying info. * + * @param commands_list $commands + * * @return int */ protected function listFull(array $commands) @@ -133,6 +138,8 @@ protected function listFull(array $commands) /** * Lists the commands only. * + * @param commands_list $commands + * * @return int */ protected function listSimple(array $commands) diff --git a/system/Commands/Translation/LocalizationFinder.php b/system/Commands/Translation/LocalizationFinder.php index ca7a1fb20230..8fed993a6ecc 100644 --- a/system/Commands/Translation/LocalizationFinder.php +++ b/system/Commands/Translation/LocalizationFinder.php @@ -213,7 +213,7 @@ private function findResolvedTranslations(string $langFileName, string $currentL /** * @param SplFileInfo|string $file * - * @return array + * @return array{foundLanguageKeys: array>, badLanguageKeys: array>} */ private function findTranslationsInFile($file): array { @@ -273,6 +273,9 @@ private function isIgnoredFile(SplFileInfo $file): bool return $file->getExtension() !== 'php'; } + /** + * @param array $language + */ private function templateFile(array $language = []): string { if ($language !== []) { @@ -337,6 +340,10 @@ private function replaceArraySyntax(string $code): string /** * Create multidimensional array from another keys + * + * @param list $fromKeys + * + * @return array */ private function buildMultiArray(array $fromKeys, string $lastArrayValue = ''): array { @@ -356,6 +363,10 @@ private function buildMultiArray(array $fromKeys, string $lastArrayValue = ''): /** * Convert multi arrays to specific CLI table rows (flat array) + * + * @param array $array + * + * @return list */ private function arrayToTableRows(string $langFileName, array $array): array { diff --git a/system/Commands/Utilities/Namespaces.php b/system/Commands/Utilities/Namespaces.php index 6469d1afc97f..51bc045759ff 100644 --- a/system/Commands/Utilities/Namespaces.php +++ b/system/Commands/Utilities/Namespaces.php @@ -91,9 +91,14 @@ public function run(array $params) CLI::table($tbody, $thead); } + /** + * @param array $params + * + * @return list + */ private function outputAllNamespaces(array $params): array { - $maxLength = $params['m']; + $maxLength = (int) $params['m']; $autoloader = service('autoloader'); @@ -129,9 +134,14 @@ private function truncate(string $string, int $max): string return $string; } + /** + * @param array $params + * + * @return list + */ private function outputCINamespaces(array $params): array { - $maxLength = $params['m']; + $maxLength = (int) $params['m']; $config = new Autoload(); diff --git a/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php b/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php index 60a79011426a..a19bd5f24188 100644 --- a/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php +++ b/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php @@ -95,9 +95,9 @@ public function get(): array /** * Adding Filters * - * @param list> $routes + * @param list, before?: string, after?: string}> $routes * - * @return list> + * @return list, before: string, after: string}> */ private function addFilters(array $routes): array { @@ -134,6 +134,9 @@ private function addFilters(array $routes): array return $routes; } + /** + * @param array{method: string, route: string, route_params: string, handler: string, params: array, before?: string, after?: string} $route + */ private function generateSampleUri(array $route, bool $longest = true): string { $sampleUri = ''; diff --git a/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php b/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php index 599e90f4d2f3..0863388b8af5 100644 --- a/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php +++ b/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php @@ -45,7 +45,7 @@ public function __construct( * * @param class-string $class * - * @return list> + * @return list}> */ public function read(string $class, string $defaultController = 'Home', string $defaultMethod = 'index'): array { @@ -128,6 +128,9 @@ public function read(string $class, string $defaultController = 'Home', string $ return $output; } + /** + * @return array{array, string} + */ private function getParameters(ReflectionMethod $method): array { $params = []; diff --git a/system/Commands/Utilities/Routes/ControllerMethodReader.php b/system/Commands/Utilities/Routes/ControllerMethodReader.php index 7c8faffd16be..aa5cddaf48d1 100644 --- a/system/Commands/Utilities/Routes/ControllerMethodReader.php +++ b/system/Commands/Utilities/Routes/ControllerMethodReader.php @@ -147,6 +147,8 @@ private function getUriByClass(string $classname): string /** * Gets a route without default controller. + * + * @return list */ private function getRouteWithoutController( string $classShortname, diff --git a/system/Commands/Utilities/Routes/FilterFinder.php b/system/Commands/Utilities/Routes/FilterFinder.php index 98a1e3659eaf..6477e1d13300 100644 --- a/system/Commands/Utilities/Routes/FilterFinder.php +++ b/system/Commands/Utilities/Routes/FilterFinder.php @@ -36,6 +36,9 @@ public function __construct(?Router $router = null, ?Filters $filters = null) $this->filters = $filters ?? service('filters'); } + /** + * @return list + */ private function getRouteFilters(string $uri): array { $this->router->handle($uri); diff --git a/tests/system/Commands/Translation/LocalizationFinderTest.php b/tests/system/Commands/Translation/LocalizationFinderTest.php index bfbd00d8bf83..f8daf59ee151 100644 --- a/tests/system/Commands/Translation/LocalizationFinderTest.php +++ b/tests/system/Commands/Translation/LocalizationFinderTest.php @@ -166,6 +166,9 @@ public function testWriteSkipsKeysAlreadyTranslatedByFramework(): void $this->assertArrayNotHasKey('pageNotFound', $generatedKeys); } + /** + * @return array + */ private function getActualTranslationOneKeys(): array { return [ @@ -179,6 +182,9 @@ private function getActualTranslationOneKeys(): array ]; } + /** + * @return array + */ private function getActualTranslationThreeKeys(): array { return [ @@ -212,6 +218,9 @@ private function getActualTranslationThreeKeys(): array ]; } + /** + * @return array + */ private function getActualTranslationFourKeys(): array { return [ diff --git a/tests/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollectorTest.php b/tests/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollectorTest.php index 3413d1a83b86..e3e7369ad131 100644 --- a/tests/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollectorTest.php +++ b/tests/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollectorTest.php @@ -31,6 +31,9 @@ protected function setUp(): void $this->resetServices(true); } + /** + * @param array>> $filterConfigFilters + */ private function createAutoRouteCollector(array $filterConfigFilters): AutoRouteCollector { $routes = service('routes'); diff --git a/tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/Dash_folder/Dash_controller.php b/tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/Dash_folder/Dash_controller.php index 486c8529d082..2a1502c6d12c 100644 --- a/tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/Dash_folder/Dash_controller.php +++ b/tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/Dash_folder/Dash_controller.php @@ -17,11 +17,11 @@ class Dash_controller extends Controller { - public function getSomemethod($p1 = ''): void + public function getSomemethod(string $p1 = ''): void { } - public function getDash_method($p1, $p2 = ''): void + public function getDash_method(string $p1, string $p2 = ''): void { } } diff --git a/tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/SubDir/BlogController.php b/tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/SubDir/BlogController.php index fee7eab80416..5054ecd8e861 100644 --- a/tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/SubDir/BlogController.php +++ b/tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/SubDir/BlogController.php @@ -21,7 +21,7 @@ public function getIndex(): void { } - public function getSomeMethod($first = ''): void + public function getSomeMethod(string $first = ''): void { } } diff --git a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php index ce813ec3631e..80f566feab75 100644 --- a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php +++ b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php @@ -47,13 +47,19 @@ protected function setUp(): void { parent::setUp(); - $this->request = service('request'); - $this->response = service('response'); + $this->request = service('request'); + + $response = service('response'); + $this->assertInstanceOf(Response::class, $response); + $this->response = $response; $this->moduleConfig = new Modules(); $this->moduleConfig->enabled = false; } + /** + * @param array $routes + */ private function createRouteCollection(array $routes = []): RouteCollectionInterface { $collection = new RouteCollection(service('locator'), $this->moduleConfig, new Routing()); @@ -72,6 +78,9 @@ private function createRouter(RouteCollectionInterface $collection): Router return new Router($collection, $this->request); } + /** + * @param array $config + */ private function createFilters(array $config = []): Filters { $config = ($config !== []) ? $config : [ @@ -159,6 +168,7 @@ public function testFindGlobalsAndRouteFilters(): void public function testFindGlobalsAndRouteFiltersWithArguments(): void { + /** @var RouteCollection $collection */ $collection = $this->createRouteCollection(); $collection->get('admin', ' AdminController::index', ['filter' => 'honeypot:arg1,arg2']); $router = $this->createRouter($collection); @@ -177,6 +187,7 @@ public function testFindGlobalsAndRouteFiltersWithArguments(): void public function testFindClassesGlobalsAndRouteFiltersWithArguments(): void { + /** @var RouteCollection $collection */ $collection = $this->createRouteCollection(); $collection->get('admin', ' AdminController::index', ['filter' => 'honeypot:arg1,arg2']); $router = $this->createRouter($collection); diff --git a/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php b/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php index 1d67afae1ce4..b2c976788b66 100644 --- a/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php +++ b/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php @@ -33,6 +33,9 @@ public function testGet(string $routeKey, string $expected): void $this->assertSame($expected, $uri); } + /** + * @return iterable + */ public static function provideGet(): iterable { yield from [ diff --git a/utils/phpstan-baseline/assign.propertyType.neon b/utils/phpstan-baseline/assign.propertyType.neon index a2a5ca34cc63..d66ece1f6c9a 100644 --- a/utils/phpstan-baseline/assign.propertyType.neon +++ b/utils/phpstan-baseline/assign.propertyType.neon @@ -1,4 +1,4 @@ -# total 20 errors +# total 19 errors parameters: ignoreErrors: @@ -12,11 +12,6 @@ parameters: count: 1 path: ../../system/Controller.php - - - message: '#^Property CodeIgniter\\Commands\\Utilities\\Routes\\FilterFinderTest\:\:\$response \(CodeIgniter\\HTTP\\Response\) does not accept CodeIgniter\\HTTP\\ResponseInterface\.$#' - count: 1 - path: ../../tests/system/Commands/Utilities/Routes/FilterFinderTest.php - - message: '#^Property CodeIgniter\\Filters\\CSRFTest\:\:\$response \(CodeIgniter\\HTTP\\Response\|null\) does not accept CodeIgniter\\HTTP\\ResponseInterface\.$#' count: 2 diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 61ebc04982b4..9c2635ecfb69 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 419 errors +# total 386 errors includes: - argument.type.neon diff --git a/utils/phpstan-baseline/method.notFound.neon b/utils/phpstan-baseline/method.notFound.neon index 67fac4e02b49..5f6c3b2e6a79 100644 --- a/utils/phpstan-baseline/method.notFound.neon +++ b/utils/phpstan-baseline/method.notFound.neon @@ -1,4 +1,4 @@ -# total 20 errors +# total 18 errors parameters: ignoreErrors: @@ -7,11 +7,6 @@ parameters: count: 1 path: ../../tests/system/CodeIgniterTest.php - - - message: '#^Call to an undefined method CodeIgniter\\Router\\RouteCollectionInterface\:\:get\(\)\.$#' - count: 2 - path: ../../tests/system/Commands/Utilities/Routes/FilterFinderTest.php - - message: '#^Call to an undefined method org\\bovigo\\vfs\\visitor\\vfsStreamVisitor\:\:getStructure\(\)\.$#' count: 2 diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index 333eaa92ae2e..af83c1d12323 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,102 +1,7 @@ -# total 282 errors +# total 256 errors parameters: ignoreErrors: - - - message: '#^Method CodeIgniter\\Commands\\ListCommands\:\:listFull\(\) has parameter \$commands with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/ListCommands.php - - - - message: '#^Method CodeIgniter\\Commands\\ListCommands\:\:listSimple\(\) has parameter \$commands with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/ListCommands.php - - - - message: '#^Method CodeIgniter\\Commands\\Translation\\LocalizationFinder\:\:arrayToTableRows\(\) has parameter \$array with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Translation/LocalizationFinder.php - - - - message: '#^Method CodeIgniter\\Commands\\Translation\\LocalizationFinder\:\:arrayToTableRows\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Translation/LocalizationFinder.php - - - - message: '#^Method CodeIgniter\\Commands\\Translation\\LocalizationFinder\:\:buildMultiArray\(\) has parameter \$fromKeys with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Translation/LocalizationFinder.php - - - - message: '#^Method CodeIgniter\\Commands\\Translation\\LocalizationFinder\:\:buildMultiArray\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Translation/LocalizationFinder.php - - - - message: '#^Method CodeIgniter\\Commands\\Translation\\LocalizationFinder\:\:findTranslationsInFile\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Translation/LocalizationFinder.php - - - - message: '#^Method CodeIgniter\\Commands\\Translation\\LocalizationFinder\:\:templateFile\(\) has parameter \$language with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Translation/LocalizationFinder.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Namespaces\:\:outputAllNamespaces\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Namespaces.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Namespaces\:\:outputAllNamespaces\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Namespaces.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Namespaces\:\:outputCINamespaces\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Namespaces.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Namespaces\:\:outputCINamespaces\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Namespaces.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\AutoRouterImproved\\AutoRouteCollector\:\:addFilters\(\) has parameter \$routes with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\AutoRouterImproved\\AutoRouteCollector\:\:addFilters\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\AutoRouterImproved\\AutoRouteCollector\:\:generateSampleUri\(\) has parameter \$route with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\AutoRouterImproved\\ControllerMethodReader\:\:getParameters\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\AutoRouterImproved\\ControllerMethodReader\:\:read\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\ControllerMethodReader\:\:getRouteWithoutController\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Routes/ControllerMethodReader.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\FilterFinder\:\:getRouteFilters\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Commands/Utilities/Routes/FilterFinder.php - - message: '#^Function log_message\(\) has parameter \$context with no value type specified in iterable type array\.$#' count: 1 @@ -772,41 +677,6 @@ parameters: count: 1 path: ../../tests/system/CodeIgniterTest.php - - - message: '#^Method CodeIgniter\\Commands\\Translation\\LocalizationFinderTest\:\:getActualTranslationFourKeys\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Commands/Translation/LocalizationFinderTest.php - - - - message: '#^Method CodeIgniter\\Commands\\Translation\\LocalizationFinderTest\:\:getActualTranslationOneKeys\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Commands/Translation/LocalizationFinderTest.php - - - - message: '#^Method CodeIgniter\\Commands\\Translation\\LocalizationFinderTest\:\:getActualTranslationThreeKeys\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Commands/Translation/LocalizationFinderTest.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\AutoRouterImproved\\AutoRouteCollectorTest\:\:createAutoRouteCollector\(\) has parameter \$filterConfigFilters with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollectorTest.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\FilterFinderTest\:\:createFilters\(\) has parameter \$config with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Commands/Utilities/Routes/FilterFinderTest.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\FilterFinderTest\:\:createRouteCollection\(\) has parameter \$routes with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Commands/Utilities/Routes/FilterFinderTest.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\SampleURIGeneratorTest\:\:provideGet\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php - - message: '#^Method CodeIgniter\\CommonFunctionsTest\:\:provideCleanPathActuallyCleaningThePaths\(\) return type has no value type specified in iterable type iterable\.$#' count: 1 diff --git a/utils/phpstan-baseline/missingType.parameter.neon b/utils/phpstan-baseline/missingType.parameter.neon index 54d2e4a72c64..8612b17071b1 100644 --- a/utils/phpstan-baseline/missingType.parameter.neon +++ b/utils/phpstan-baseline/missingType.parameter.neon @@ -1,27 +1,7 @@ -# total 12 errors +# total 8 errors parameters: ignoreErrors: - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\AutoRouterImproved\\Controllers\\Dash_folder\\Dash_controller\:\:getDash_method\(\) has parameter \$p1 with no type specified\.$#' - count: 1 - path: ../../tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/Dash_folder/Dash_controller.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\AutoRouterImproved\\Controllers\\Dash_folder\\Dash_controller\:\:getDash_method\(\) has parameter \$p2 with no type specified\.$#' - count: 1 - path: ../../tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/Dash_folder/Dash_controller.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\AutoRouterImproved\\Controllers\\Dash_folder\\Dash_controller\:\:getSomemethod\(\) has parameter \$p1 with no type specified\.$#' - count: 1 - path: ../../tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/Dash_folder/Dash_controller.php - - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\AutoRouterImproved\\Controllers\\SubDir\\BlogController\:\:getSomeMethod\(\) has parameter \$first with no type specified\.$#' - count: 1 - path: ../../tests/system/Commands/Utilities/Routes/AutoRouterImproved/Controllers/SubDir/BlogController.php - - message: '#^Method CodeIgniter\\Config\\FactoriesTest\:\:getFactoriesStaticProperty\(\) has parameter \$params with no type specified\.$#' count: 1