Skip to content

Commit 58c8dbf

Browse files
Change NoReturnArrayVariableListRule to ignore array spreads (#139)
1 parent 434d05d commit 58c8dbf

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/Rules/NoReturnArrayVariableListRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ private function resolveExprCount(Array_ $array): int
156156
continue;
157157
}
158158

159+
if ($item->unpack === true) {
160+
continue;
161+
}
162+
159163
++$exprCount;
160164
}
161165

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanRules\Tests\Rules\NoReturnArrayVariableListRule\Fixture;
6+
7+
final class SkipArraySpreads
8+
{
9+
public function run($value)
10+
{
11+
$a = [1, 2, 3];
12+
$b = [4, 5, 6];
13+
return [...$a, ...$b];
14+
}
15+
}
16+

tests/Rules/NoReturnArrayVariableListRule/NoReturnArrayVariableListRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static function provideData(): Iterator
3030
yield [__DIR__ . '/Fixture/SkipNews.php', []];
3131
yield [__DIR__ . '/Fixture/ValueObject/SkipValueObject.php', []];
3232
yield [__DIR__ . '/Fixture/SkipParentMethod.php', []];
33+
yield [__DIR__ . '/Fixture/SkipArraySpreads.php', []];
3334
}
3435

3536
/**

0 commit comments

Comments
 (0)