Skip to content

Commit

Permalink
Remove UpdateFileNameByClassNameFileSystemRector niche rule that was …
Browse files Browse the repository at this point in the history
…added just for example sake (#3849)
  • Loading branch information
TomasVotruba committed May 14, 2023
1 parent 6568360 commit 33e59ee
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 247 deletions.
20 changes: 2 additions & 18 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 409 Rules Overview
# 408 Rules Overview

<br>

Expand Down Expand Up @@ -58,7 +58,7 @@

- [Renaming](#renaming) (11)

- [Restoration](#restoration) (3)
- [Restoration](#restoration) (2)

- [Strict](#strict) (6)

Expand Down Expand Up @@ -7389,22 +7389,6 @@ Convert missing class reference to string

<br>

### UpdateFileNameByClassNameFileSystemRector

Rename file to respect class name

- class: [`Rector\Restoration\Rector\ClassLike\UpdateFileNameByClassNameFileSystemRector`](../rules/Restoration/Rector/ClassLike/UpdateFileNameByClassNameFileSystemRector.php)

```diff
-// app/SomeClass.php
+// app/AnotherClass.php
class AnotherClass
{
}
```

<br>

## Strict

### AddConstructorParentCallRector
Expand Down
7 changes: 0 additions & 7 deletions packages/Testing/PHPUnit/Behavior/MovingFilesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ private function resolveAddedFilePathsWithContents(): array
$addedFilePathsWithContents = $this->removedAndAddedFilesCollector->getAddedFilesWithContent();
$nodesWithFileDestinationPrinter = $this->getService(NodesWithFileDestinationPrinter::class);

$movedFiles = $this->removedAndAddedFilesCollector->getMovedFiles();

foreach ($movedFiles as $movedFile) {
$fileContent = $nodesWithFileDestinationPrinter->printNodesWithFileDestination($movedFile);
$addedFilePathsWithContents[] = new AddedFileWithContent($movedFile->getNewFilePath(), $fileContent);
}

$addedFilesWithNodes = $this->removedAndAddedFilesCollector->getAddedFilesWithNodes();
if ($addedFilesWithNodes === []) {
return $addedFilePathsWithContents;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions src/Application/FileSystem/RemovedAndAddedFilesCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Rector\Core\Application\FileSystem;

use Rector\Core\ValueObject\Application\File;
use Rector\Core\ValueObject\Application\MovedFile;
use Rector\FileSystemRector\Contract\AddedFileInterface;
use Rector\FileSystemRector\ValueObject\AddedFileWithContent;
use Rector\FileSystemRector\ValueObject\AddedFileWithNodes;
Expand All @@ -22,11 +20,6 @@ final class RemovedAndAddedFilesCollector
*/
private array $addedFiles = [];

/**
* @var MovedFile[]
*/
private array $movedFiles = [];

public function removeFile(string $filePath): void
{
$this->removedFilePaths[] = $filePath;
Expand All @@ -50,15 +43,6 @@ public function isFileRemoved(string $filePath): bool
return true;
}

foreach ($this->movedFiles as $movedFile) {
$file = $movedFile->getFile();
if ($movedFile->getFilePath() !== $file->getFilePath()) {
continue;
}

return true;
}

return false;
}

Expand Down Expand Up @@ -108,20 +92,6 @@ public function getRemovedFilesCount(): int
public function reset(): void
{
$this->addedFiles = [];
$this->movedFiles = [];
$this->removedFilePaths = [];
}

public function addMovedFile(File $file, string $newPathName): void
{
$this->movedFiles[] = new MovedFile($file, $newPathName);
}

/**
* @return MovedFile[]
*/
public function getMovedFiles(): array
{
return $this->movedFiles;
}
}
27 changes: 0 additions & 27 deletions src/Application/FileSystem/RemovedAndAddedFilesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function run(Configuration $configuration): void
{
$this->processAddedFilesWithContent($configuration);
$this->processAddedFilesWithNodes($configuration);
$this->processMovedFilesWithNodes($configuration);

$this->processDeletedFiles($configuration);
}
Expand Down Expand Up @@ -86,30 +85,4 @@ private function processAddedFilesWithNodes(Configuration $configuration): void
}
}
}

private function processMovedFilesWithNodes(Configuration $configuration): void
{
foreach ($this->removedAndAddedFilesCollector->getMovedFiles() as $movedFile) {
$fileContent = $this->nodesWithFileDestinationPrinter->printNodesWithFileDestination($movedFile);

if ($configuration->isDryRun()) {
$message = sprintf(
'File "%s" will be moved to "%s"',
$movedFile->getFilePath(),
$movedFile->getNewFilePath()
);
$this->rectorOutputStyle->note($message);
} else {
$this->filesystem->dumpFile($movedFile->getNewFilePath(), $fileContent);
$this->filesystem->remove($movedFile->getFilePath());

$message = sprintf(
'File "%s" was moved to "%s"',
$movedFile->getFilePath(),
$movedFile->getNewFilePath()
);
$this->rectorOutputStyle->note($message);
}
}
}
}
6 changes: 3 additions & 3 deletions src/PhpParser/Printer/NodesWithFileDestinationPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\Core\PhpParser\Printer;

use Rector\Core\Contract\PhpParser\NodePrinterInterface;
use Rector\FileSystemRector\Contract\FileWithNodesInterface;
use Rector\FileSystemRector\ValueObject\AddedFileWithNodes;
use Rector\PostRector\Application\PostFileProcessor;

final class NodesWithFileDestinationPrinter
Expand All @@ -16,9 +16,9 @@ public function __construct(
) {
}

public function printNodesWithFileDestination(FileWithNodesInterface $fileWithNodes): string
public function printNodesWithFileDestination(AddedFileWithNodes $addedFileWithNodes): string
{
$nodes = $this->postFileProcessor->traverse($fileWithNodes->getNodes());
$nodes = $this->postFileProcessor->traverse($addedFileWithNodes->getNodes());
return $this->nodePrinter->prettyPrintFile($nodes);
}
}
40 changes: 0 additions & 40 deletions src/ValueObject/Application/MovedFile.php

This file was deleted.

0 comments on commit 33e59ee

Please sign in to comment.