Skip to content

Commit c2b88d5

Browse files
committed
static fixes
1 parent ac79922 commit c2b88d5

File tree

6 files changed

+36
-37
lines changed

6 files changed

+36
-37
lines changed

phpstan.neon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,10 @@ parameters:
4343
# see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110
4444
- '#Doing instanceof PHPStan\\Type\\.+ is error\-prone and deprecated#'
4545

46-
- identifier: instanceof.alwaysTrue
46+
#- identifier: instanceof.alwaysTrue
4747

4848
# false positive
4949
-
5050
identifier: assign.propertyType
5151
message: '#Property PhpParser\\Node\\Identifier\:\:\$name \(non\-empty\-string\) does not accept string#'
5252
path: rules/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector.php
53-
54-
# handle next
55-
-
56-
identifier: symplify.forbiddenNode
57-
message: '#switch#'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rector\PHPUnit\Tests\Rector\MethodCall\AssertEqualsToSameRector\Fixture\DateTimeImmutable;
7+
8+
final class Test extends TestCase
9+
{
10+
public function test()
11+
{
12+
$expected = ['something' => ['date' => new DateTimeImmutable('2022-10-31 12:32:33')]];
13+
$date = new DateTimeImmutable('2022-10-31 12:32:33');
14+
$actual = compact('date');
15+
16+
self::assertEquals($expected, $actual);
17+
}
18+
}
19+
20+
?>

rules/AnnotationsToAttributes/Rector/Class_/RequiresAnnotationWithValueToAttributeRector.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,22 @@ public function refactor(Node $node): ?Node
104104

105105
$hasChanged = false;
106106

107-
if ($node instanceof Class_) {
108-
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
109-
if ($phpDocInfo instanceof PhpDocInfo) {
110-
$requiresAttributeGroups = $this->handleRequires($phpDocInfo);
111-
if ($requiresAttributeGroups !== []) {
112-
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
113-
$node->attrGroups = array_merge($node->attrGroups, $requiresAttributeGroups);
114-
$this->removeMethodRequiresAnnotations($phpDocInfo);
115-
$hasChanged = true;
116-
}
107+
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
108+
if ($phpDocInfo instanceof PhpDocInfo) {
109+
$requiresAttributeGroups = $this->handleRequires($phpDocInfo);
110+
if ($requiresAttributeGroups !== []) {
111+
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
112+
$node->attrGroups = array_merge($node->attrGroups, $requiresAttributeGroups);
113+
$this->removeMethodRequiresAnnotations($phpDocInfo);
114+
$hasChanged = true;
117115
}
118116
}
119117

120-
return $hasChanged ? $node : null;
118+
if ($hasChanged) {
119+
return $node;
120+
}
121+
122+
return null;
121123
}
122124

123125
/**

rules/CodeQuality/Rector/ClassMethod/DataProviderArrayItemsNewLinedRector.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod;
66

77
use PhpParser\Node;
8-
use PhpParser\Node\ArrayItem;
98
use PhpParser\Node\Expr\Array_;
109
use PhpParser\Node\Stmt\ClassMethod;
1110
use PhpParser\Node\Stmt\Return_;
@@ -136,10 +135,6 @@ public function refactor(Node $node): ?Node
136135
private function shouldRePrint(Array_ $array): bool
137136
{
138137
foreach ($array->items as $key => $item) {
139-
if (! $item instanceof ArrayItem) {
140-
continue;
141-
}
142-
143138
if (! isset($array->items[$key + 1])) {
144139
continue;
145140
}

rules/PHPUnit100/Rector/Class_/RemoveNamedArgsInDataProviderRector.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
namespace Rector\PHPUnit\PHPUnit100\Rector\Class_;
66

77
use PhpParser\Node;
8-
use PhpParser\Node\ArrayItem;
98
use PhpParser\Node\Expr;
109
use PhpParser\Node\Expr\Array_;
1110
use PhpParser\Node\Expr\Yield_;
12-
use PhpParser\Node\Scalar\Int_;
1311
use PhpParser\Node\Stmt\Class_;
1412
use PhpParser\Node\Stmt\Expression;
1513
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
@@ -127,18 +125,12 @@ private function handleArray(Array_ $array): bool
127125
{
128126
$hasChanged = false;
129127
foreach ($array->items as $item) {
130-
if (! $item instanceof ArrayItem) {
131-
continue;
132-
}
133-
134128
if (! $item->key instanceof Expr) {
135129
continue;
136130
}
137131

138-
if (! $item->key instanceof Int_ && $item->key instanceof Expr) {
139-
$item->key = null;
140-
$hasChanged = true;
141-
}
132+
$item->key = null;
133+
$hasChanged = true;
142134
}
143135

144136
return $hasChanged;

src/NodeFactory/ConsecutiveIfsFactory.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Rector\PHPUnit\NodeFactory;
66

77
use PhpParser\Node\Arg;
8-
use PhpParser\Node\ArrayItem;
98
use PhpParser\Node\Expr\Array_;
109
use PhpParser\Node\Expr\ArrayDimFetch;
1110
use PhpParser\Node\Expr\ArrowFunction;
@@ -44,10 +43,6 @@ public function createIfs(MethodCall $withConsecutiveMethodCall, MethodCall $num
4443
if ($withConsecutiveArg->value instanceof Array_) {
4544
$array = $withConsecutiveArg->value;
4645
foreach ($array->items as $assertKey => $assertArrayItem) {
47-
if (! $assertArrayItem instanceof ArrayItem) {
48-
continue;
49-
}
50-
5146
if (! $assertArrayItem->value instanceof MethodCall) {
5247
$parametersDimFetch = new ArrayDimFetch(new Variable('parameters'), new Int_($assertKey));
5348
$args = [new Arg($assertArrayItem->value), new Arg($parametersDimFetch)];

0 commit comments

Comments
 (0)