Skip to content

Commit

Permalink
[DowngradePhp81] Fix DowngradeArraySpreadStringKeyRector (#1371)
Browse files Browse the repository at this point in the history
* [DowngradePhp81] Fix DowngradeArraySpreadStringKeyRector

* Fixed 🎉
  • Loading branch information
samsonasik committed Dec 3, 2021
1 parent 81a50ac commit 493d4e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Expand Up @@ -26,7 +26,7 @@ class ArraySpreadStringKey
$parts = ['a' => 'b'];
$parts2 = ['c' => 'd'];

$result = [...$parts, ...$parts2];
$result = array_merge($parts, $parts2);
}
}

Expand Down
Expand Up @@ -30,7 +30,7 @@ class ArraySpreadStringKeyByDoc
/** @var array<string, string> $parts2 */
$parts2 = $this->data2();

$result = [...$parts, ...$parts2];
$result = array_merge($parts, $parts2);
}
}

Expand Down
Expand Up @@ -7,7 +7,8 @@
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\ArrayType;
use PHPStan\Type\IntegerType;
use Rector\DowngradePhp74\Rector\Array_\DowngradeArraySpreadRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -81,7 +82,17 @@ private function shouldSkip(Array_ $array): bool
continue;
}

if (! $item->key instanceof String_) {
if (! $item->unpack) {
continue;
}

$type = $this->nodeTypeResolver->getType($item->value);
if (! $type instanceof ArrayType) {
continue;
}

$keyType = $type->getKeyType();
if ($keyType instanceof IntegerType) {
return true;
}
}
Expand Down

0 comments on commit 493d4e6

Please sign in to comment.