Skip to content

Commit 73a21bc

Browse files
committed
[DowngradePhp84] Add DowngradeArrayAllRector
1 parent 2ac3e9f commit 73a21bc

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

rector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
->withPhpSets(php82: true)
1313
->withSets([PHPUnitSetList::PHPUNIT_100, PHPUnitSetList::PHPUNIT_CODE_QUALITY])
1414
->withPreparedSets(
15+
deadCode: true,
1516
codeQuality: true,
1617
codingStyle: true,
17-
deadCode: true,
18+
typeDeclarations: true,
1819
privatization: true,
1920
naming: true,
20-
typeDeclarations: true,
2121
earlyReturn: true,
2222
rectorPreset: true
2323
)->withPaths([

rules/DowngradePhp84/Rector/Expression/DowngradeArrayAllRector.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Expr\ArrowFunction;
99
use PhpParser\Node\Expr\Assign;
10-
use PhpParser\Node\Expr\ClassConstFetch;
11-
use PhpParser\Node\Expr\Closure;
1210
use PhpParser\Node\Expr\ConstFetch;
1311
use PhpParser\Node\Expr\FuncCall;
14-
use PhpParser\Node\Expr\MethodCall;
15-
use PhpParser\Node\Identifier;
1612
use PhpParser\Node\Name;
17-
use PhpParser\Node\Name\FullyQualified;
13+
use PhpParser\Node\Stmt\Break_;
1814
use PhpParser\Node\Stmt\Expression;
1915
use PhpParser\Node\Stmt\Foreach_;
2016
use PhpParser\Node\Stmt\If_;
@@ -90,20 +86,14 @@ public function refactor(Node $node): ?array
9086

9187
$if = new If_($args[1]->value->expr, [
9288
'stmts' => [
93-
new Expression(new Assign(
94-
$node->expr->var,
95-
new ConstFetch(new Name('false'))
96-
)),
97-
new Node\Stmt\Break_(),
89+
new Expression(new Assign($node->expr->var, new ConstFetch(new Name('false')))),
90+
new Break_(),
9891
],
9992
]);
10093

10194
return [
10295
// init
103-
new Expression(new Assign(
104-
$node->expr->var,
105-
new ConstFetch(new Name('true'))
106-
)),
96+
new Expression(new Assign($node->expr->var, new ConstFetch(new Name('true')))),
10797

10898
// foreach loop
10999
new Foreach_(
@@ -112,10 +102,12 @@ public function refactor(Node $node): ?array
112102
isset($args[1]->value->params[1]->var)
113103
? [
114104
'keyVar' => $args[1]->value->params[1]->var,
115-
'stmts' => [$if]
105+
'stmts' => [$if],
116106
]
117-
: ['stmts' => [$if]],
118-
)
107+
: [
108+
'stmts' => [$if],
109+
],
110+
),
119111
];
120112
}
121113
}

0 commit comments

Comments
 (0)