Skip to content

Commit e420c03

Browse files
authored
Merge pull request #7940 from samsonasik/str-vars
[PHPStan] Add @var string[] on array of string, detected by enable StringifyStrNeedlesRector
2 parents 367c308 + 29e3186 commit e420c03

4 files changed

Lines changed: 26 additions & 9 deletions

File tree

rector.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
use Rector\Php70\Rector\FuncCall\RandomFunctionRector;
3838
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
3939
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
40-
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
4140
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
4241
use Rector\PHPUnit\Set\PHPUnitSetList;
4342
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
@@ -80,7 +79,6 @@
8079
__DIR__ . '/tests/system/Filters/fixtures',
8180
__DIR__ . '/tests/_support',
8281
JsonThrowOnErrorRector::class,
83-
StringifyStrNeedlesRector::class,
8482
YieldDataProviderRector::class,
8583

8684
RemoveUnusedPrivateMethodRector::class => [

system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ final class ControllerMethodReader
2626
*/
2727
private string $namespace;
2828

29+
/**
30+
* @var array<int, string>
31+
* @phpstan-var list<string>
32+
*/
2933
private array $httpMethods;
3034

3135
/**

system/Email/Email.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ class Email
352352
* Character sets valid for 7-bit encoding,
353353
* excluding language suffix.
354354
*
355-
* @var array
355+
* @var array<int, string>
356+
* @phpstan-var list<string>
356357
*/
357358
protected $baseCharsets = [
358359
'us-ascii',

system/Router/RouteCollection.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,9 +1293,16 @@ protected function fillRouteParams(string $from, ?array $params = null): string
12931293
return '/' . ltrim($from, '/');
12941294
}
12951295

1296-
// Build our resulting string, inserting the $params in
1297-
// the appropriate places.
1298-
foreach ($matches[0] as $index => $pattern) {
1296+
/**
1297+
* Build our resulting string, inserting the $params in
1298+
* the appropriate places.
1299+
*
1300+
* @var array<int, string> $patterns
1301+
* @phpstan-var list<string> $patterns
1302+
*/
1303+
$patterns = $matches[0];
1304+
1305+
foreach ($patterns as $index => $pattern) {
12991306
if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
13001307
throw RouterException::forInvalidParameterType();
13011308
}
@@ -1338,9 +1345,16 @@ protected function buildReverseRoute(string $from, array $params): string
13381345
$locale = $params[$placeholderCount];
13391346
}
13401347

1341-
// Build our resulting string, inserting the $params in
1342-
// the appropriate places.
1343-
foreach ($matches[0] as $index => $placeholder) {
1348+
/**
1349+
* Build our resulting string, inserting the $params in
1350+
* the appropriate places.
1351+
*
1352+
* @var array<int, string> $placeholders
1353+
* @phpstan-var list<string> $placeholders
1354+
*/
1355+
$placeholders = $matches[0];
1356+
1357+
foreach ($placeholders as $index => $placeholder) {
13441358
if (! isset($params[$index])) {
13451359
throw new InvalidArgumentException(
13461360
'Missing argument for "' . $placeholder . '" in route "' . $from . '".'

0 commit comments

Comments
 (0)