Skip to content

Commit c263ce2

Browse files
authored
simplify DowngradeIteratorCountToArrayRector (#350)
1 parent 2365f06 commit c263ce2

File tree

3 files changed

+2
-41
lines changed

3 files changed

+2
-41
lines changed

phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,3 @@ parameters:
9999
-
100100
identifier: symplify.seeAnnotationToTest
101101
path: rules/DowngradePhp85/Rector/StmtsAwareInterface/DowngradePipeOperatorRector.php
102-
103-
-
104-
identifier: rector.noIntegerRefactorReturn
105-
path: rules/DowngradePhp82/Rector/FuncCall/DowngradeIteratorCountToArrayRector.php

rules-tests/DowngradePhp82/Rector/FuncCall/DowngradeIteratorCountToArrayRector/Fixture/skip_in_ternary.php.inc

Lines changed: 0 additions & 16 deletions
This file was deleted.

rules/DowngradePhp82/Rector/FuncCall/DowngradeIteratorCountToArrayRector.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
use PhpParser\Node\Expr\New_;
1111
use PhpParser\Node\Expr\Ternary;
1212
use PhpParser\Node\Name\FullyQualified;
13-
use PhpParser\NodeVisitor;
1413
use PHPStan\Type\Type;
1514
use PHPStan\Type\TypeCombinator;
1615
use Rector\NodeAnalyzer\ArgsAnalyzer;
17-
use Rector\PhpParser\Node\BetterNodeFinder;
1816
use Rector\Rector\AbstractRector;
1917
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2018
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -30,7 +28,6 @@ final class DowngradeIteratorCountToArrayRector extends AbstractRector
3028
{
3129
public function __construct(
3230
private readonly ArgsAnalyzer $argsAnalyzer,
33-
private readonly BetterNodeFinder $betterNodeFinder
3431
) {
3532
}
3633

@@ -67,26 +64,10 @@ function test(array|Traversable $data) {
6764
}
6865

6966
/**
70-
* @param Ternary|FuncCall $node
71-
* @return null|FuncCall|NodeVisitor::DONT_TRAVERSE_CHILDREN
67+
* @param FuncCall $node
7268
*/
73-
public function refactor(Node $node): null|FuncCall|int
69+
public function refactor(Node $node): null|FuncCall
7470
{
75-
if ($node instanceof Ternary) {
76-
$hasIsArrayCheck = (bool) $this->betterNodeFinder->findFirst(
77-
$node,
78-
fn (Node $subNode): bool => $subNode instanceof FuncCall && $this->isName($subNode, 'is_array')
79-
);
80-
81-
// get tgype...
82-
83-
if ($hasIsArrayCheck) {
84-
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
85-
}
86-
87-
return null;
88-
}
89-
9071
if (! $this->isNames($node, ['iterator_count', 'iterator_to_array'])) {
9172
return null;
9273
}

0 commit comments

Comments
 (0)