Skip to content

Commit

Permalink
Merge pull request #7940 from samsonasik/str-vars
Browse files Browse the repository at this point in the history
[PHPStan] Add @var string[] on array of string, detected by enable StringifyStrNeedlesRector
  • Loading branch information
samsonasik authored Sep 14, 2023
2 parents 367c308 + 29e3186 commit e420c03
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
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

0 comments on commit e420c03

Please sign in to comment.