EVOLUTION-NINJA
Edit File: RemovedAndAddedFilesProcessor.php
<?php declare (strict_types=1); namespace Rector\Core\Application\FileSystem; use Rector\Core\PhpParser\Printer\NodesWithFileDestinationPrinter; use Rector\Core\ValueObject\Configuration; use RectorPrefix20211231\Symfony\Component\Console\Style\SymfonyStyle; use RectorPrefix20211231\Symplify\SmartFileSystem\SmartFileSystem; /** * Adds and removes scheduled file */ final class RemovedAndAddedFilesProcessor { /** * @readonly * @var \Symplify\SmartFileSystem\SmartFileSystem */ private $smartFileSystem; /** * @readonly * @var \Rector\Core\PhpParser\Printer\NodesWithFileDestinationPrinter */ private $nodesWithFileDestinationPrinter; /** * @readonly * @var \Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector */ private $removedAndAddedFilesCollector; /** * @readonly * @var \Symfony\Component\Console\Style\SymfonyStyle */ private $symfonyStyle; public function __construct(\RectorPrefix20211231\Symplify\SmartFileSystem\SmartFileSystem $smartFileSystem, \Rector\Core\PhpParser\Printer\NodesWithFileDestinationPrinter $nodesWithFileDestinationPrinter, \Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector $removedAndAddedFilesCollector, \RectorPrefix20211231\Symfony\Component\Console\Style\SymfonyStyle $symfonyStyle) { $this->smartFileSystem = $smartFileSystem; $this->nodesWithFileDestinationPrinter = $nodesWithFileDestinationPrinter; $this->removedAndAddedFilesCollector = $removedAndAddedFilesCollector; $this->symfonyStyle = $symfonyStyle; } public function run(\Rector\Core\ValueObject\Configuration $configuration) : void { $this->processAddedFilesWithContent($configuration); $this->processAddedFilesWithNodes($configuration); $this->processMovedFilesWithNodes($configuration); $this->processDeletedFiles($configuration); } private function processDeletedFiles(\Rector\Core\ValueObject\Configuration $configuration) : void { foreach ($this->removedAndAddedFilesCollector->getRemovedFiles() as $removedFile) { $relativePath = $removedFile->getRelativeFilePathFromDirectory(\getcwd()); if ($configuration->isDryRun()) { $message = \sprintf('File "%s" will be removed', $relativePath); $this->symfonyStyle->warning($message); } else { $message = \sprintf('File "%s" was removed', $relativePath); $this->symfonyStyle->warning($message); $this->smartFileSystem->remove($removedFile->getPathname()); } } } private function processAddedFilesWithContent(\Rector\Core\ValueObject\Configuration $configuration) : void { foreach ($this->removedAndAddedFilesCollector->getAddedFilesWithContent() as $addedFileWithContent) { if ($configuration->isDryRun()) { $message = \sprintf('File "%s" will be added', $addedFileWithContent->getFilePath()); $this->symfonyStyle->note($message); } else { $this->smartFileSystem->dumpFile($addedFileWithContent->getFilePath(), $addedFileWithContent->getFileContent()); $message = \sprintf('File "%s" was added', $addedFileWithContent->getFilePath()); $this->symfonyStyle->note($message); } } } private function processAddedFilesWithNodes(\Rector\Core\ValueObject\Configuration $configuration) : void { foreach ($this->removedAndAddedFilesCollector->getAddedFilesWithNodes() as $addedFileWithNode) { $fileContent = $this->nodesWithFileDestinationPrinter->printNodesWithFileDestination($addedFileWithNode); if ($configuration->isDryRun()) { $message = \sprintf('File "%s" will be added', $addedFileWithNode->getFilePath()); $this->symfonyStyle->note($message); } else { $this->smartFileSystem->dumpFile($addedFileWithNode->getFilePath(), $fileContent); $message = \sprintf('File "%s" was added', $addedFileWithNode->getFilePath()); $this->symfonyStyle->note($message); } } } private function processMovedFilesWithNodes(\Rector\Core\ValueObject\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->symfonyStyle->note($message); } else { $this->smartFileSystem->dumpFile($movedFile->getNewFilePath(), $fileContent); $this->smartFileSystem->remove($movedFile->getFilePath()); $message = \sprintf('File "%s" was moved to "%s"', $movedFile->getFilePath(), $movedFile->getNewFilePath()); $this->symfonyStyle->note($message); } } } }