Skip to content

Commit 047cc85

Browse files
committed
Fix: Stop ignoring associative arrays in sub-classes of PHPUnit\Framework\TestCase
1 parent 36db413 commit 047cc85

File tree

4 files changed

+4
-87
lines changed

4 files changed

+4
-87
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ For a full diff see [`1.3.0...main`][1.3.0...main].
1111
### Changed
1212

1313
- Required `rector/rector:^2.0.11` ([#199]), by [@localheinz]
14+
- Adjusted `Rules\Arrays\SortAssociativeArrayByKeyRector` to stop ignoring associative arrays used in sub-classes of `PHPUnit\Framework\TestCase` ([#200]), by [@localheinz]
1415

1516
## [`1.3.0`][1.3.0]
1617

@@ -129,5 +130,6 @@ For a full diff see [`fd198f0...0.1.0`][fd198f0...0.1.0].
129130
[#162]: https://github.com/ergebnis/rector-rules/pull/162
130131
[#171]: https://github.com/ergebnis/rector-rules/pull/171
131132
[#199]: https://github.com/ergebnis/rector-rules/pull/199
133+
[#200]: https://github.com/ergebnis/rector-rules/pull/200
132134

133135
[@localheinz]: https://github.com/localheinz

infection.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"logs": {
44
"text": ".build/infection/infection-log.txt"
55
},
6-
"minCoveredMsi": 83,
7-
"minMsi": 72,
6+
"minCoveredMsi": 80,
7+
"minMsi": 65,
88
"phpUnit": {
99
"configDir": "test\/Unit"
1010
},

src/Arrays/SortAssociativeArrayByKeyRector.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,11 @@
1414
namespace Ergebnis\Rector\Rules\Arrays;
1515

1616
use PhpParser\Node;
17-
use PHPStan\Reflection\ClassReflection;
1817
use Rector\Rector;
19-
use Rector\Reflection;
2018
use Symplify\RuleDocGenerator;
2119

2220
final class SortAssociativeArrayByKeyRector extends Rector\AbstractRector
2321
{
24-
private Reflection\ReflectionResolver $reflectionResolver;
25-
26-
public function __construct(Reflection\ReflectionResolver $reflectionResolver)
27-
{
28-
$this->reflectionResolver = $reflectionResolver;
29-
}
30-
3122
public function getRuleDefinition(): RuleDocGenerator\ValueObject\RuleDefinition
3223
{
3324
return new RuleDocGenerator\ValueObject\RuleDefinition(
@@ -79,10 +70,6 @@ public function refactor(Node $node): ?Node
7970
return null;
8071
}
8172

82-
if ($this->isScopeInTest($node)) {
83-
return null;
84-
}
85-
8673
/** @var array<int, Node\Expr\ArrayItem> $items */
8774
$items = \array_filter($node->items, static function ($item): bool {
8875
if (!$item instanceof Node\Expr\ArrayItem) {
@@ -119,25 +106,4 @@ public function refactor(Node $node): ?Node
119106

120107
return $node;
121108
}
122-
123-
private function isScopeInTest(Node $node): bool
124-
{
125-
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
126-
127-
if (!$classReflection instanceof ClassReflection) {
128-
return false;
129-
}
130-
131-
$parentClass = $classReflection->getParentClass();
132-
133-
while ($parentClass instanceof ClassReflection) {
134-
if ($parentClass->getName() === 'PHPUnit\Framework\TestCase') {
135-
return true;
136-
}
137-
138-
$parentClass = $parentClass->getParentClass();
139-
}
140-
141-
return false;
142-
}
143109
}

test/Fixture/Arrays/SortAssociativeArrayByKeyRector/test.php.inc

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

0 commit comments

Comments
 (0)