Skip to content

Commit

Permalink
Fix SingleInArrayToCompareRector if array item is variadic (#3640)
Browse files Browse the repository at this point in the history
* Add failing test fixture for SingleInArrayToCompareRector

Based on https://getrector.com/demo/001ae62c-7857-4ce2-b4c1-8be77fd37568

* fix SingleInArrayToCompareRector in case the array item is variadic

* rename SingleInArrayToCompareRector unpacking fixture as suggested by
@samsonasik
  • Loading branch information
raoz committed Apr 21, 2023
1 parent ae99f13 commit add5582
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector\Fixture;

final class SkipUnpackArrayItemExists
{
public function run()
{
$a = ['a', 'b'];
echo in_array('a', [...$a]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public function refactor(Node $node): ?Node
return null;
}

if($firstArrayItem->unpack){
return null;
}

if (! isset($node->args[0])) {
return null;
}
Expand Down

0 comments on commit add5582

Please sign in to comment.