Skip to content

Commit 4e3bd30

Browse files
committed
apply rector
1 parent a1a0e41 commit 4e3bd30

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

rules/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Rector\TypeDeclaration\Rector\FuncCall;
66

7+
use PhpParser\Node\Expr\Variable;
8+
use PhpParser\Node\Expr\Instanceof_;
79
use PhpParser\Node;
810
use PhpParser\Node\Expr\ArrayDimFetch;
911
use PhpParser\Node\Expr\ArrowFunction;
@@ -24,7 +26,7 @@
2426
final class AddArrowFunctionParamArrayWhereDimFetchRector extends AbstractRector implements MinPhpVersionInterface
2527
{
2628
public function __construct(
27-
private BetterNodeFinder $betterNodeFinder
29+
private readonly BetterNodeFinder $betterNodeFinder
2830
) {
2931
}
3032

@@ -90,7 +92,7 @@ public function refactor(Node $node): ?Node
9092
$dimFetchVariableNames = $this->resolveDimFetchVariableNames($closureExpr);
9193

9294
foreach ($closureExpr->getParams() as $closureParam) {
93-
if ($closureParam->type instanceof \PhpParser\Node) {
95+
if ($closureParam->type instanceof Node) {
9496
// param is known already
9597
continue;
9698
}
@@ -126,19 +128,15 @@ public function provideMinPhpVersion(): int
126128
*/
127129
private function resolveDimFetchVariableNames(Closure|ArrowFunction $closureExpr): array
128130
{
129-
if ($closureExpr instanceof ArrowFunction) {
130-
$closureNodes = [$closureExpr->expr];
131-
} else {
132-
$closureNodes = $closureExpr->stmts;
133-
}
131+
$closureNodes = $closureExpr instanceof ArrowFunction ? [$closureExpr->expr] : $closureExpr->stmts;
134132

135133
/** @var ArrayDimFetch[] $arrayDimFetches */
136134
$arrayDimFetches = $this->betterNodeFinder->findInstancesOfScoped($closureNodes, ArrayDimFetch::class);
137135

138136
$usedDimFetchVariableNames = [];
139137

140138
foreach ($arrayDimFetches as $arrayDimFetch) {
141-
if ($arrayDimFetch->var instanceof Node\Expr\Variable) {
139+
if ($arrayDimFetch->var instanceof Variable) {
142140
$usedDimFetchVariableNames[] = (string) $this->getName($arrayDimFetch->var);
143141
}
144142
}
@@ -151,11 +149,7 @@ private function resolveDimFetchVariableNames(Closure|ArrowFunction $closureExpr
151149
*/
152150
private function resolveIsArrayVariables(Closure|ArrowFunction $closureExpr): array
153151
{
154-
if ($closureExpr instanceof ArrowFunction) {
155-
$closureNodes = [$closureExpr->expr];
156-
} else {
157-
$closureNodes = $closureExpr->stmts;
158-
}
152+
$closureNodes = $closureExpr instanceof ArrowFunction ? [$closureExpr->expr] : $closureExpr->stmts;
159153

160154
/** @var FuncCall[] $funcCalls */
161155
$funcCalls = $this->betterNodeFinder->findInstancesOfScoped($closureNodes, FuncCall::class);
@@ -169,7 +163,7 @@ private function resolveIsArrayVariables(Closure|ArrowFunction $closureExpr): ar
169163

170164
$firstArgExpr = $funcCall->getArgs()[0]
171165
->value;
172-
if (! $firstArgExpr instanceof Node\Expr\Variable) {
166+
if (! $firstArgExpr instanceof Variable) {
173167
continue;
174168
}
175169

@@ -184,19 +178,15 @@ private function resolveIsArrayVariables(Closure|ArrowFunction $closureExpr): ar
184178
*/
185179
private function resolveInstanceofVariables(Closure|ArrowFunction $closureExpr): array
186180
{
187-
if ($closureExpr instanceof ArrowFunction) {
188-
$closureNodes = [$closureExpr->expr];
189-
} else {
190-
$closureNodes = $closureExpr->stmts;
191-
}
181+
$closureNodes = $closureExpr instanceof ArrowFunction ? [$closureExpr->expr] : $closureExpr->stmts;
192182

193-
/** @var Node\Expr\Instanceof_[] $instanceOfs */
194-
$instanceOfs = $this->betterNodeFinder->findInstancesOfScoped($closureNodes, Node\Expr\Instanceof_::class);
183+
/** @var Instanceof_[] $instanceOfs */
184+
$instanceOfs = $this->betterNodeFinder->findInstancesOfScoped($closureNodes, Instanceof_::class);
195185

196186
$variableNames = [];
197187

198188
foreach ($instanceOfs as $instanceOf) {
199-
if (! $instanceOf->expr instanceof Node\Expr\Variable) {
189+
if (! $instanceOf->expr instanceof Variable) {
200190
continue;
201191
}
202192

0 commit comments

Comments
 (0)