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 array<int, string>
* @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,7 +352,8 @@ class Email
* Character sets valid for 7-bit encoding,
* excluding language suffix.
*
* @var array
* @var array<int, string>
* @phpstan-var list<string>
*/
protected $baseCharsets = [
'us-ascii',
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 @@ protected function fillRouteParams(string $from, ?array $params = null): string
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 array<int, string> $patterns
* @phpstan-var list<string> $patterns
*/
$patterns = $matches[0];

foreach ($patterns as $index => $pattern) {
if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
throw RouterException::forInvalidParameterType();
}
Expand Down Expand Up @@ -1338,9 +1345,16 @@ protected function buildReverseRoute(string $from, array $params): string
$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 array<int, string> $placeholders
* @phpstan-var list<string> $placeholders
*/
$placeholders = $matches[0];

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