Skip to content
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

[PHPStan] Add @var string[] on array of string, detected by enable StringifyStrNeedlesRector #7940

Merged
merged 8 commits into from
Sep 14, 2023
2 changes: 0 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use Rector\Php70\Rector\FuncCall\RandomFunctionRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
Expand Down Expand Up @@ -80,7 +79,6 @@
__DIR__ . '/tests/system/Filters/fixtures',
__DIR__ . '/tests/_support',
JsonThrowOnErrorRector::class,
StringifyStrNeedlesRector::class,
YieldDataProviderRector::class,

RemoveUnusedPrivateMethodRector::class => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ final class ControllerMethodReader
*/
private string $namespace;

/**
* @var arrray<int, string>
samsonasik marked this conversation as resolved.
Show resolved Hide resolved
* @phpstan-var list<string>
*/
private array $httpMethods;

/**
Expand Down
3 changes: 2 additions & 1 deletion system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,10 @@
* Character sets valid for 7-bit encoding,
* excluding language suffix.
*
* @var array
* @var arrray<int, string>
* @phpstan-var list<string>
*/
protected $baseCharsets = [

Check failure on line 358 in system/Email/Email.php

View workflow job for this annotation

GitHub Actions / Psalm Analysis

UndefinedDocblockClass

system/Email/Email.php:358:5: UndefinedDocblockClass: Docblock-defined class, interface or enum named CodeIgniter\Email\arrray does not exist (see https://psalm.dev/200)
'us-ascii',
'iso-2022-',
];
Expand Down
26 changes: 20 additions & 6 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1293,9 +1293,16 @@
return '/' . ltrim($from, '/');
}

// Build our resulting string, inserting the $params in
// the appropriate places.
foreach ($matches[0] as $index => $pattern) {
/**
* Build our resulting string, inserting the $params in
* the appropriate places.
*
* @var arrray<int, string> $patterns
* @phpstan-var list<string> $patterns
*/
$patterns = $matches[0];

Check failure on line 1303 in system/Router/RouteCollection.php

View workflow job for this annotation

GitHub Actions / Psalm Analysis

UndefinedDocblockClass

system/Router/RouteCollection.php:1303:9: UndefinedDocblockClass: Docblock-defined class, interface or enum named CodeIgniter\Router\arrray does not exist (see https://psalm.dev/200)

foreach ($patterns as $index => $pattern) {
if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
throw RouterException::forInvalidParameterType();
}
Expand Down Expand Up @@ -1338,9 +1345,16 @@
$locale = $params[$placeholderCount];
}

// Build our resulting string, inserting the $params in
// the appropriate places.
foreach ($matches[0] as $index => $placeholder) {
/**
* Build our resulting string, inserting the $params in
* the appropriate places.
*
* @var arrray<int, string> $patterns
* @phpstan-var list<string> $patterns
samsonasik marked this conversation as resolved.
Show resolved Hide resolved
*/
$placeholders = $matches[0];

Check failure on line 1355 in system/Router/RouteCollection.php

View workflow job for this annotation

GitHub Actions / Psalm Analysis

UndefinedDocblockClass

system/Router/RouteCollection.php:1355:9: UndefinedDocblockClass: Docblock-defined class, interface or enum named CodeIgniter\Router\arrray does not exist (see https://psalm.dev/200)

Check failure on line 1355 in system/Router/RouteCollection.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Variable $patterns in PHPDoc tag @var does not match assigned variable $placeholders.

foreach ($placeholders as $index => $placeholder) {
if (! isset($params[$index])) {
throw new InvalidArgumentException(
'Missing argument for "' . $placeholder . '" in route "' . $from . '".'
Expand Down
Loading