Skip to content

Commit 72190d5

Browse files
committed
[CodingStyle] Skip non-native array type on PHP 7.4 for ArraySpreadInsteadOfArrayMergeRector
1 parent 15eb8c2 commit 72190d5

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
4+
5+
class SkipDocblockBasedTypeArrayMerge
6+
{
7+
/**
8+
* @param array<int, string> $iter1
9+
* @param array<int, string> $iter2
10+
*/
11+
public function run($iter1, $iter2)
12+
{
13+
$values = array_merge($iter1, $iter2);
14+
}
15+
}

rules/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ private function shouldSkipArrayForInvalidKeys(Expr $expr): bool
135135
$type = $this->getType($expr);
136136

137137
if ($type->getIterableKeyType()->isInteger()->yes()) {
138+
if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS)) {
139+
$nativeType = $this->nodeTypeResolver->getNativeType($expr);
140+
return ! $nativeType->isArray()->yes();
141+
}
142+
138143
return false;
139144
}
140145

0 commit comments

Comments
 (0)