Skip to content

Commit 397d1cf

Browse files
committed
make sue of rector runner
1 parent 2c26991 commit 397d1cf

6 files changed

Lines changed: 15 additions & 32 deletions

File tree

‎src/Application/FileProcessor.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __construct(
4444
private RectorParser $rectorParser,
4545
private NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator,
4646
private UsedImportsResolver $usedImportsResolver,
47+
private RectorRegistry $rectorRegistry,
4748
) {
4849
}
4950

@@ -59,6 +60,9 @@ public function processFile(File $file, Configuration $configuration): FileProce
5960
$fileHasChanged = false;
6061
$filePath = $file->getFilePath();
6162

63+
$currentRectors = $this->rectorRegistry->forFile($file);
64+
$this->rectorNodeTraverser->refreshPhpRectors($currentRectors);
65+
6266
do {
6367
$file->changeHasChanged(false);
6468

‎src/Application/RectorRegistry.php‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Rector\Contract\Rector\HTMLAverseRectorInterface;
88
use Rector\Contract\Rector\RectorInterface;
9-
use Rector\Skipper\Skipper\Skipper;
109
use Rector\ValueObject\Application\File;
1110

1211
/**
@@ -19,7 +18,6 @@ final class RectorRegistry
1918
*/
2019
public function __construct(
2120
private array $rectors,
22-
private readonly Skipper $skipper
2321
) {
2422
}
2523

@@ -41,13 +39,6 @@ public function forFile(File $file): array
4139
{
4240
$rectorsForPath = [];
4341
foreach ($this->rectors as $rector) {
44-
var_dump($rector);
45-
var_dump($file->getFilePath());
46-
47-
if ($this->skipper->shouldSkipRectorAndFile($rector, $file->getFilePath())) {
48-
continue;
49-
}
50-
5142
if ($rector instanceof HTMLAverseRectorInterface && $file->containsHTML()) {
5243
continue;
5344
}

‎src/PhpParser/NodeTraverser/RectorNodeTraverser.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function traverse(array $nodes): array
6262

6363
/**
6464
* @param RectorInterface[] $rectors
65-
* @api used in tests to update the active rules
6665
*
6766
* @internal Used only in Rector core, not supported outside. Might change any time.
6867
*/

‎src/PostRector/Application/PostFileProcessor.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public function traverse(array $stmts, File $file): array
7171
*/
7272
private function shouldSkipPostRector(PostRectorInterface $postRector, string $filePath, array $stmts): bool
7373
{
74-
if ($this->skipper->shouldSkipRectorAndFile($postRector, $filePath)) {
75-
return true;
76-
}
74+
// if ($this->skipper->shouldSkipRectorAndFile($postRector, $filePath)) {
75+
// return true;
76+
// }
7777

7878
// skip renaming if rename class rector is skipped
7979
if ($postRector instanceof ClassRenamingPostRector && $this->skipper->shouldSkipRectorAndFile(

‎src/Rector/RectorRunner.php‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Rector\Application\ChangedNodeScopeRefresher;
1414
use Rector\Application\Provider\CurrentFileProvider;
1515
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
16-
use Rector\Contract\Rector\HTMLAverseRectorInterface;
1716
use Rector\Contract\Rector\RectorInterface;
1817
use Rector\Exception\ShouldNotHappenException;
1918
use Rector\NodeDecorator\CreatedByRuleDecorator;
@@ -56,11 +55,6 @@ public function __construct(
5655
public function run(RectorInterface $rector, Node $node): int|Node|null|array
5756
{
5857
$file = $this->getFile();
59-
60-
if ($rector instanceof HTMLAverseRectorInterface && $file->containsHTML()) {
61-
return null;
62-
}
63-
6458
$filePath = $file->getFilePath();
6559

6660
// node already changed by this rule in a previous pass → hard skip
@@ -71,14 +65,14 @@ public function run(RectorInterface $rector, Node $node): int|Node|null|array
7165
// class/path skip is configured for this rule and file: run the rule on a deep clone to learn
7266
// whether it would actually have changed anything. Only a skip that prevents a real change
7367
// counts as used; the original node is left untouched, so the file stays skipped either way.
74-
// $skipMatch = $this->skipper->matchSkip($rector, $filePath);
75-
// if ($skipMatch instanceof SkipMatch) {
76-
// if ($rector->refactor($this->cloneNode($node)) !== null) {
77-
// $this->skipper->markSkipUsed($skipMatch);
78-
// }
79-
//
80-
// return null;
81-
// }
68+
$skipMatch = $this->skipper->matchSkip($rector, $filePath);
69+
if ($skipMatch instanceof SkipMatch) {
70+
if ($rector->refactor($this->cloneNode($node)) !== null) {
71+
$this->skipper->markSkipUsed($skipMatch);
72+
}
73+
74+
return null;
75+
}
8276

8377
// ensure origNode pulled before refactor to avoid changed during refactor, ref https://3v4l.org/YMEGN
8478
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node;

‎tests/Application/RectorRegistryTest.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ protected function tearDown(): void
3434

3535
public function testForFile(): void
3636
{
37-
$file = new File(__DIR__ . '/skipped_directory/some_file.php', '');
38-
$rectorsForPath = $this->rectorRegistry->forFile($file);
39-
40-
$this->assertSame([], $rectorsForPath);
41-
4237
$file = new File(__DIR__ . '/some_file.php', '');
4338
$rectorsForPath = $this->rectorRegistry->forFile($file);
4439

0 commit comments

Comments
 (0)