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,9 @@ final class ControllerMethodReader
*/
private string $namespace;

/**
* @var string[]
samsonasik marked this conversation as resolved.
Show resolved Hide resolved
*/
private array $httpMethods;

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class Email
* Character sets valid for 7-bit encoding,
* excluding language suffix.
*
* @var array
* @var string[]
samsonasik marked this conversation as resolved.
Show resolved Hide resolved
*/
protected $baseCharsets = [
'us-ascii',
Expand Down
24 changes: 18 additions & 6 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1293,9 +1293,15 @@ 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 string[] $patterns
samsonasik marked this conversation as resolved.
Show resolved Hide resolved
*/
$patterns = $matches[0];

foreach ($patterns as $index => $pattern) {
if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
throw RouterException::forInvalidParameterType();
}
Expand Down Expand Up @@ -1338,9 +1344,15 @@ 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 string[] $placeholders
samsonasik marked this conversation as resolved.
Show resolved Hide resolved
*/
$placeholders = $matches[0];

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