Skip to content

Commit 1e31208

Browse files
committed
add MakeUseOfContaintsStmtsRector
1 parent 01ef160 commit 1e31208

File tree

147 files changed

+639
-469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+639
-469
lines changed

build/build-preload.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,6 @@ private function findPhpParserFilesAndSortThem(string $vendorDir): array
362362
}
363363

364364
return array_values($fileInfos);
365-
366-
// $ContainsStmts = new SplFileInfo(__DIR__ . '/../src/Contract/PhpParser/Node/ContainsStmts.php');
367-
// array_splice($fileInfos, 1, 0, [$ContainsStmts]);
368-
369-
return $fileInfos;
370365
}
371366

372367
/**

phpstan.neon

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ parameters:
332332

333333
-
334334
identifier: symplify.seeAnnotationToTest
335-
path: utils/PHPStan/Rule/PreferDirectIsNameRule.php
335+
path: utils/
336336

337337
-
338338
identifier: arrayValues.list
@@ -356,3 +356,7 @@ parameters:
356356
-
357357
identifier: offsetAccess.invalidOffset
358358
path: src/CustomRules/SimpleNodeDumper.php
359+
360+
-
361+
message: '#Method Rector\\Utils\\Rector\\MakeUseOfContaintsStmtsRector\:\:refactor\(\) should return 4\|PhpParser\\Node\\Expr\\BinaryOp\\Identical\|PhpParser\\Node\\Expr\\MethodCall\|null but returns int\|null#'
362+
path: utils/Rector/MakeUseOfContaintsStmtsRector.php

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Rector\Config\RectorConfig;
77
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
88
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
9+
use Rector\Utils\Rector\MakeUseOfContaintsStmtsRector;
910

1011
return RectorConfig::configure()
1112
->withPreparedSets(
@@ -35,6 +36,7 @@
3536
__DIR__ . '/config',
3637
__DIR__ . '/build/build-preload.php',
3738
])
39+
->withRules([MakeUseOfContaintsStmtsRector::class])
3840
->withRootFiles()
3941
->withImportNames(removeUnusedImports: true)
4042
->withSkip([

rules/Assert/NodeAnalyzer/ExistingAssertStaticCallResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ final class ExistingAssertStaticCallResolver
1818
*/
1919
public function resolve(ClassMethod $classMethod): array
2020
{
21-
if ($classMethod->stmts === null) {
21+
if ($classMethod->getStmts() === []) {
2222
return [];
2323
}
2424

2525
$existingAssertCallHashes = [];
2626
$standard = new Standard();
2727

28-
foreach ($classMethod->stmts as $currentStmt) {
28+
foreach ($classMethod->getStmts() as $currentStmt) {
2929
if (! $currentStmt instanceof Expression) {
3030
continue;
3131
}

rules/Assert/Rector/ClassMethod/AddAssertArrayFromClassMethodDocblockRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function refactor(Node $node): ?ClassMethod
108108
return null;
109109
}
110110

111-
if ($node->stmts === null || $node->isAbstract()) {
111+
if ($node->getStmts() === [] || $node->isAbstract()) {
112112
return null;
113113
}
114114

rules/CodeQuality/NodeAnalyzer/ForeachAnalyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public function __construct(
2626
*/
2727
public function matchAssignItemsOnlyForeachArrayVariable(Foreach_ $foreach): ?Expr
2828
{
29-
if (count($foreach->stmts) !== 1) {
29+
if (count($foreach->getStmts()) !== 1) {
3030
return null;
3131
}
3232

33-
$onlyStatement = $foreach->stmts[0];
33+
$onlyStatement = $foreach->getStmts()[0];
3434
if ($onlyStatement instanceof Expression) {
3535
$onlyStatement = $onlyStatement->expr;
3636
}

rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function refactor(Node $node): ?Node
9696
}
9797

9898
$isChanged = false;
99-
$this->traverseNodesWithCallable($node->stmts, function (Node $node) use (
99+
$this->traverseNodesWithCallable($node->getStmts(), function (Node $node) use (
100100
$caughtThrowableVariable,
101101
&$isChanged
102102
): ?int {

rules/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function refactor(Node $node): ?Node
124124
}
125125

126126
$hasChanged = false;
127-
$this->traverseNodesWithCallable((array) $node->stmts, static function (Node $node) use (
127+
$this->traverseNodesWithCallable((array) $node->getStmts(), static function (Node $node) use (
128128
&$hasChanged
129129
): int|null|Return_ {
130130
if ($node instanceof Class_ || $node instanceof Function_ || $node instanceof Closure) {

rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function refactor(Node $node): ?Node
8181
return null;
8282
}
8383

84-
if ($constructClassMethod->stmts === null) {
84+
if ($constructClassMethod->getStmts() === []) {
8585
return null;
8686
}
8787

@@ -182,14 +182,14 @@ private function refactorProperty(
182182
AttributeKey::COMMENTS,
183183
array_merge(
184184
$classStmt->getComments(),
185-
isset($constructClassMethod->stmts[$key])
186-
? $constructClassMethod->stmts[$key]->getComments()
185+
isset($constructClassMethod->getStmts()[$key])
186+
? $constructClassMethod->getStmts()[$key]->getComments()
187187
: [],
188188
)
189189
);
190190

191191
// remove assign
192-
unset($constructClassMethod->stmts[$key]);
192+
unset($constructClassMethod->getStmts()[$key]);
193193

194194
return true;
195195
}

rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function getNodeTypes(): array
7272
*/
7373
public function refactor(Node $node): ?Node
7474
{
75-
if ($node->stmts === null) {
75+
if ($node->getStmts() === []) {
7676
return null;
7777
}
7878

@@ -162,11 +162,11 @@ private function shouldSkipForeach(Foreach_ $foreach): bool
162162
return true;
163163
}
164164

165-
if (count($foreach->stmts) > 1) {
165+
if (count($foreach->getStmts()) > 1) {
166166
return true;
167167
}
168168

169-
if (! $foreach->stmts[0] instanceof If_) {
169+
if (! $foreach->getStmts()[0] instanceof If_) {
170170
return true;
171171
}
172172

@@ -196,7 +196,7 @@ private function matchNodes(Equal|Identical $binaryOp, Expr $expr): ?TwoNodeMatc
196196

197197
private function isIfBodyABoolReturnNode(If_ $if): bool
198198
{
199-
$ifStatement = $if->stmts[0];
199+
$ifStatement = $if->getStmts()[0];
200200
if (! $ifStatement instanceof Return_) {
201201
return false;
202202
}

0 commit comments

Comments
 (0)