Skip to content
Open
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
7 changes: 7 additions & 0 deletions system/Commands/ListCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -133,6 +138,8 @@ protected function listFull(array $commands)
/**
* Lists the commands only.
*
* @param commands_list $commands
*
* @return int
*/
protected function listSimple(array $commands)
Expand Down
13 changes: 12 additions & 1 deletion system/Commands/Translation/LocalizationFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private function findResolvedTranslations(string $langFileName, string $currentL
/**
* @param SplFileInfo|string $file
*
* @return array<string, array>
* @return array{foundLanguageKeys: array<string, array<string, string>>, badLanguageKeys: array<int, array<int, string>>}
*/
private function findTranslationsInFile($file): array
{
Expand Down Expand Up @@ -273,6 +273,9 @@ private function isIgnoredFile(SplFileInfo $file): bool
return $file->getExtension() !== 'php';
}

/**
* @param array<array-key, mixed> $language
*/
private function templateFile(array $language = []): string
{
if ($language !== []) {
Expand Down Expand Up @@ -337,6 +340,10 @@ private function replaceArraySyntax(string $code): string

/**
* Create multidimensional array from another keys
*
* @param list<string> $fromKeys
*
* @return array<array-key, mixed>
*/
private function buildMultiArray(array $fromKeys, string $lastArrayValue = ''): array
{
Expand All @@ -356,6 +363,10 @@ private function buildMultiArray(array $fromKeys, string $lastArrayValue = ''):

/**
* Convert multi arrays to specific CLI table rows (flat array)
*
* @param array<array-key, mixed> $array
*
* @return list<array{string, string}>
*/
private function arrayToTableRows(string $langFileName, array $array): array
{
Expand Down
14 changes: 12 additions & 2 deletions system/Commands/Utilities/Namespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,14 @@ public function run(array $params)
CLI::table($tbody, $thead);
}

/**
* @param array<array-key, int|string|null> $params
*
* @return list<array{string, string, string}>
*/
private function outputAllNamespaces(array $params): array
{
$maxLength = $params['m'];
$maxLength = (int) $params['m'];

$autoloader = service('autoloader');

Expand Down Expand Up @@ -129,9 +134,14 @@ private function truncate(string $string, int $max): string
return $string;
}

/**
* @param array<array-key, int|string|null> $params
*
* @return list<array{string, string, string}>
*/
private function outputCINamespaces(array $params): array
{
$maxLength = $params['m'];
$maxLength = (int) $params['m'];

$config = new Autoload();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public function get(): array
/**
* Adding Filters
*
* @param list<array<string, array|string>> $routes
* @param list<array{method: string, route: string, route_params: string, handler: string, params: array<string, bool>, before?: string, after?: string}> $routes
*
* @return list<array<string, array|string>>
* @return list<array{method: string, route: string, route_params: string, handler: string, params: array<string, bool>, before: string, after: string}>
*/
private function addFilters(array $routes): array
{
Expand Down Expand Up @@ -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<string, bool>, before?: string, after?: string} $route
*/
private function generateSampleUri(array $route, bool $longest = true): string
{
$sampleUri = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(
*
* @param class-string $class
*
* @return list<array<string, array|string>>
* @return list<array{method: string, route: string, route_params: string, handler: string, params: array<string, bool>}>
*/
public function read(string $class, string $defaultController = 'Home', string $defaultMethod = 'index'): array
{
Expand Down Expand Up @@ -128,6 +128,9 @@ public function read(string $class, string $defaultController = 'Home', string $
return $output;
}

/**
* @return array{array<string, bool>, string}
*/
private function getParameters(ReflectionMethod $method): array
{
$params = [];
Expand Down
2 changes: 2 additions & 0 deletions system/Commands/Utilities/Routes/ControllerMethodReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ private function getUriByClass(string $classname): string

/**
* Gets a route without default controller.
*
* @return list<array{route: string, handler: string}>
*/
private function getRouteWithoutController(
string $classShortname,
Expand Down
3 changes: 3 additions & 0 deletions system/Commands/Utilities/Routes/FilterFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function __construct(?Router $router = null, ?Filters $filters = null)
$this->filters = $filters ?? service('filters');
}

/**
* @return list<string>
*/
private function getRouteFilters(string $uri): array
{
$this->router->handle($uri);
Expand Down
9 changes: 9 additions & 0 deletions tests/system/Commands/Translation/LocalizationFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public function testWriteSkipsKeysAlreadyTranslatedByFramework(): void
$this->assertArrayNotHasKey('pageNotFound', $generatedKeys);
}

/**
* @return array<string, string>
*/
private function getActualTranslationOneKeys(): array
{
return [
Expand All @@ -179,6 +182,9 @@ private function getActualTranslationOneKeys(): array
];
}

/**
* @return array<string, mixed>
*/
private function getActualTranslationThreeKeys(): array
{
return [
Expand Down Expand Up @@ -212,6 +218,9 @@ private function getActualTranslationThreeKeys(): array
];
}

/**
* @return array<string, mixed>
*/
private function getActualTranslationFourKeys(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ protected function setUp(): void
$this->resetServices(true);
}

/**
* @param array<string, array<string, list<string>>> $filterConfigFilters
*/
private function createAutoRouteCollector(array $filterConfigFilters): AutoRouteCollector
{
$routes = service('routes');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getIndex(): void
{
}

public function getSomeMethod($first = ''): void
public function getSomeMethod(string $first = ''): void
{
}
}
15 changes: 13 additions & 2 deletions tests/system/Commands/Utilities/Routes/FilterFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> $routes
*/
private function createRouteCollection(array $routes = []): RouteCollectionInterface
{
$collection = new RouteCollection(service('locator'), $this->moduleConfig, new Routing());
Expand All @@ -72,6 +78,9 @@ private function createRouter(RouteCollectionInterface $collection): Router
return new Router($collection, $this->request);
}

/**
* @param array<string, mixed> $config
*/
private function createFilters(array $config = []): Filters
{
$config = ($config !== []) ? $config : [
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function testGet(string $routeKey, string $expected): void
$this->assertSame($expected, $uri);
}

/**
* @return iterable<string, array{string, string}>
*/
public static function provideGet(): iterable
{
yield from [
Expand Down
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/assign.propertyType.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 20 errors
# total 19 errors

parameters:
ignoreErrors:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/phpstan-baseline/loader.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 419 errors
# total 386 errors

includes:
- argument.type.neon
Expand Down
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/method.notFound.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 20 errors
# total 18 errors

parameters:
ignoreErrors:
Expand All @@ -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
Expand Down
Loading
Loading