Skip to content

Commit 0340447

Browse files
committed
fix: List postrectors in the list of applied rules
Resolves: rectorphp/rector#9373
1 parent df88764 commit 0340447

8 files changed

Lines changed: 32 additions & 11 deletions

File tree

src/ChangesReporting/ValueObject/RectorWithLineChange.php

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

77
use Rector\Contract\Rector\RectorInterface;
8+
use Rector\PostRector\Contract\Rector\PostRectorInterface;
89
use Symplify\EasyParallel\Contract\SerializableInterface;
910
use Webmozart\Assert\Assert;
1011

@@ -21,26 +22,26 @@
2122
private const KEY_LINE = 'line';
2223

2324
/**
24-
* @var class-string<RectorInterface>
25+
* @var class-string<RectorInterface|PostRectorInterface>
2526
*/
2627
private string $rectorClass;
2728

2829
/**
29-
* @param class-string<RectorInterface>|RectorInterface $rectorClass
30+
* @param class-string<RectorInterface|PostRectorInterface>|RectorInterface|PostRectorInterface $rectorClass
3031
*/
3132
public function __construct(
32-
string|RectorInterface $rectorClass,
33+
string|RectorInterface|PostRectorInterface $rectorClass,
3334
private int $line
3435
) {
35-
if ($rectorClass instanceof RectorInterface) {
36+
if ($rectorClass instanceof RectorInterface || $rectorClass instanceof PostRectorInterface) {
3637
$rectorClass = $rectorClass::class;
3738
}
3839

3940
$this->rectorClass = $rectorClass;
4041
}
4142

4243
/**
43-
* @return class-string<RectorInterface>
44+
* @return class-string<RectorInterface|PostRectorInterface>
4445
*/
4546
public function getRectorClass(): string
4647
{
@@ -63,7 +64,7 @@ public static function decode(array $json): self
6364
}
6465

6566
/**
66-
* @return array{rector_class: class-string<RectorInterface>, line: int}
67+
* @return array{rector_class: class-string<RectorInterface|PostRectorInterface>, line: int}
6768
*/
6869
public function jsonSerialize(): array
6970
{

src/PostRector/Rector/AbstractPostRector.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
abstract class AbstractPostRector extends NodeVisitorAbstract implements PostRectorInterface
1414
{
15-
private File|null $file = null;
15+
protected File $file;
1616

1717
/**
1818
* @param Stmt[] $stmts
@@ -29,8 +29,6 @@ public function setFile(File $file): void
2929

3030
public function getFile(): File
3131
{
32-
Assert::isInstanceOf($this->file, File::class);
33-
3432
return $this->file;
3533
}
3634
}

src/PostRector/Rector/ClassRenamingPostRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpParser\Node\Stmt;
99
use PhpParser\Node\Stmt\Namespace_;
1010
use PhpParser\NodeVisitor;
11+
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
1112
use Rector\CodingStyle\Application\UseImportsRemover;
1213
use Rector\Configuration\Option;
1314
use Rector\Configuration\Parameter\SimpleParameterProvider;
@@ -44,6 +45,10 @@ public function beforeTraverse(array $nodes): array
4445
$removedUses = $this->renamedClassesDataCollector->getOldClasses();
4546
$node->stmts = $this->useImportsRemover->removeImportsFromStmts($node->stmts, $removedUses);
4647

48+
// notify this rule changing code
49+
$rectorWithLineChange = new RectorWithLineChange(self::class, $node->getStartLine());
50+
$this->file->addRectorClassWithLine($rectorWithLineChange);
51+
4752
break;
4853
}
4954
}

src/PostRector/Rector/DocblockNameImportingPostRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpParser\Node\Stmt;
1010
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
1111
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
12+
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
1213
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
1314
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockNameImporter;
1415
use Rector\PostRector\Guard\AddUseStatementGuard;
@@ -39,6 +40,10 @@ public function enterNode(Node $node): Node|null
3940
return null;
4041
}
4142

43+
// notify this rule changing code
44+
$rectorWithLineChange = new RectorWithLineChange(self::class, $node->getStartLine());
45+
$this->file->addRectorClassWithLine($rectorWithLineChange);
46+
4247
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
4348
return $node;
4449
}

src/PostRector/Rector/NameImportingPostRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpParser\Node\Stmt;
1010
use PhpParser\Node\Stmt\GroupUse;
1111
use PhpParser\Node\Stmt\Use_;
12+
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
1213
use Rector\CodingStyle\Node\NameImporter;
1314
use Rector\Naming\Naming\UseImportsResolver;
1415
use Rector\PostRector\Guard\AddUseStatementGuard;
@@ -42,6 +43,10 @@ public function enterNode(Node $node): Node|null
4243
return null;
4344
}
4445

46+
// notify this rule changing code
47+
$rectorWithLineChange = new RectorWithLineChange(self::class, $node->getStartLine());
48+
$this->file->addRectorClassWithLine($rectorWithLineChange);
49+
4550
return $this->nameImporter->importName($node, $this->getFile(), $this->currentUses);
4651
}
4752

src/PostRector/Rector/UnusedImportRemovingPostRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PhpParser\Node\UseItem;
1919
use PhpParser\NodeVisitor;
2020
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
21+
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
2122
use Rector\NodeTypeResolver\Node\AttributeKey;
2223
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
2324
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
@@ -93,6 +94,10 @@ public function enterNode(Node $node): ?Node
9394
return null;
9495
}
9596

97+
// notify this rule changing code
98+
$rectorWithLineChange = new RectorWithLineChange(self::class, $node->getStartLine());
99+
$this->file->addRectorClassWithLine($rectorWithLineChange);
100+
96101
$node->stmts = array_values($node->stmts);
97102
return $node;
98103
}

src/Testing/PHPUnit/ValueObject/RectorTestResult.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Rector\Testing\PHPUnit\ValueObject;
66

77
use Rector\Contract\Rector\RectorInterface;
8+
use Rector\PostRector\Contract\Rector\PostRectorInterface;
89
use Rector\ValueObject\ProcessResult;
910

1011
/**
@@ -24,7 +25,7 @@ public function getChangedContents(): string
2425
}
2526

2627
/**
27-
* @return array<class-string<RectorInterface>>
28+
* @return array<class-string<RectorInterface|PostRectorInterface>>
2829
*/
2930
public function getAppliedRectorClasses(): array
3031
{

src/ValueObject/Reporting/FileDiff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
99
use Rector\Contract\Rector\RectorInterface;
1010
use Rector\Parallel\ValueObject\BridgeItem;
11+
use Rector\PostRector\Contract\Rector\PostRectorInterface;
1112
use Symplify\EasyParallel\Contract\SerializableInterface;
1213
use Webmozart\Assert\Assert;
1314

@@ -81,7 +82,7 @@ public function getRectorShortClasses(): array
8182
}
8283

8384
/**
84-
* @return array<class-string<RectorInterface>>
85+
* @return array<class-string<RectorInterface|PostRectorInterface>>
8586
*/
8687
public function getRectorClasses(): array
8788
{

0 commit comments

Comments
 (0)