Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/sonarcube.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: SonarCube

on: push
on:
push:
branches:
- master

jobs:
sonnar_cloud:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
use PHPStan\Type\ArrayType;
Expand All @@ -20,6 +21,7 @@
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\Core\ValueObject\PhpVersionFeature;
use Symfony\Component\Finder\Finder;

/**
* @see https://wiki.php.net/rfc/spread_operator_for_array
Expand Down Expand Up @@ -117,10 +119,16 @@ private function refactorArray(FuncCall $funcCall): ?Array_
return $array;
}

private function refactorIteratorToArray(FuncCall $funcCall): Array_
private function refactorIteratorToArray(FuncCall $funcCall): ?Array_
{
$value = $funcCall->args[0]->value;

if ($this->isMethodCallWithFinderAndGetIterator($value)) {
return null;
}

$array = new Array_();
$array->items[] = $this->createUnpackedArrayItem($funcCall->args[0]->value);
$array->items[] = $this->createUnpackedArrayItem($value);

return $array;
}
Expand Down Expand Up @@ -191,4 +199,21 @@ private function isConstantArrayTypeWithStringKeyType(Type $type): bool

return false;
}

/**
* Special type, not resolved by PHPStan correctly.
* Has string keys, has to be skipped
*/
private function isMethodCallWithFinderAndGetIterator(Expr $expr): bool
{
if (! $expr instanceof MethodCall) {
return false;
}

if (! $this->isObjectType($expr->var, Finder::class)) {
return false;
}

return $this->isName($expr->name, 'getIterator');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Php74\Tests\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\Fixture;

use Symfony\Component\Finder\Finder;

class SkipGetIreator
{
public function run()
{
$finder = Finder::create()->files()
->in(__DIR__ . '/Source');

$files = iterator_to_array($finder->getIterator());
}
}