Updated Rector to commit 33e59eeadf3da67db8dcdebfc8bef3701a17592a

33e59eeadf Remove UpdateFileNameByClassNameFileSystemRector niche rule that was added just for example sake (#3849)
This commit is contained in:
Tomas Votruba 2023-05-14 16:07:53 +00:00
parent 18b46b9b72
commit e02a2a45af
12 changed files with 17 additions and 196 deletions

View File

@ -1,4 +1,4 @@
# 409 Rules Overview
# 408 Rules Overview
<br>
@ -58,7 +58,7 @@
- [Renaming](#renaming) (11)
- [Restoration](#restoration) (3)
- [Restoration](#restoration) (2)
- [Strict](#strict) (6)
@ -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

View File

@ -33,11 +33,6 @@ trait MovingFilesTrait
{
$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;

View File

@ -1,69 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Restoration\Rector\ClassLike;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassLike;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\Restoration\Rector\ClassLike\UpdateFileNameByClassNameFileSystemRector\UpdateFileNameByClassNameFileSystemRectorTest
*/
final class UpdateFileNameByClassNameFileSystemRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector
*/
private $removedAndAddedFilesCollector;
public function __construct(RemovedAndAddedFilesCollector $removedAndAddedFilesCollector)
{
$this->removedAndAddedFilesCollector = $removedAndAddedFilesCollector;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Rename file to respect class name', [new CodeSample(<<<'CODE_SAMPLE'
// app/SomeClass.php
class AnotherClass
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
// app/AnotherClass.php
class AnotherClass
{
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassLike::class];
}
/**
* @param ClassLike $node
*/
public function refactor(Node $node) : ?Node
{
$className = $this->getName($node);
if ($className === null) {
return null;
}
$classShortName = $this->nodeNameResolver->getShortName($className);
$filePath = $this->file->getFilePath();
$basename = \pathinfo($filePath, \PATHINFO_FILENAME);
if ($classShortName === $basename) {
return null;
}
// no match → rename file
$newFileLocation = \dirname($filePath) . \DIRECTORY_SEPARATOR . $classShortName . '.php';
$this->removedAndAddedFilesCollector->addMovedFile($this->file, $newFileLocation);
return null;
}
}

View File

@ -3,8 +3,6 @@
declare (strict_types=1);
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;
@ -18,10 +16,6 @@ final class RemovedAndAddedFilesCollector
* @var AddedFileInterface[]
*/
private $addedFiles = [];
/**
* @var MovedFile[]
*/
private $movedFiles = [];
public function removeFile(string $filePath) : void
{
$this->removedFilePaths[] = $filePath;
@ -41,13 +35,6 @@ final class RemovedAndAddedFilesCollector
}
return \true;
}
foreach ($this->movedFiles as $movedFile) {
$file = $movedFile->getFile();
if ($movedFile->getFilePath() !== $file->getFilePath()) {
continue;
}
return \true;
}
return \false;
}
/**
@ -89,18 +76,6 @@ final class RemovedAndAddedFilesCollector
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;
}
}

View File

@ -50,7 +50,6 @@ final class RemovedAndAddedFilesProcessor
{
$this->processAddedFilesWithContent($configuration);
$this->processAddedFilesWithNodes($configuration);
$this->processMovedFilesWithNodes($configuration);
$this->processDeletedFiles($configuration);
}
private function processDeletedFiles(Configuration $configuration) : void
@ -96,19 +95,4 @@ final class RemovedAndAddedFilesProcessor
}
}
}
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);
}
}
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '656836093ea0abd96860af062fdf6f67afe1f504';
public const PACKAGE_VERSION = '33e59eeadf3da67db8dcdebfc8bef3701a17592a';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-14 16:53:35';
public const RELEASE_DATE = '2023-05-14 16:02:19';
/**
* @var int
*/

View File

@ -4,7 +4,7 @@ declare (strict_types=1);
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
{
@ -23,9 +23,9 @@ final class NodesWithFileDestinationPrinter
$this->nodePrinter = $nodePrinter;
$this->postFileProcessor = $postFileProcessor;
}
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);
}
}

View File

@ -1,44 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Core\ValueObject\Application;
use PhpParser\Node\Stmt;
use Rector\FileSystemRector\Contract\FileWithNodesInterface;
final class MovedFile implements FileWithNodesInterface
{
/**
* @readonly
* @var \Rector\Core\ValueObject\Application\File
*/
private $file;
/**
* @readonly
* @var string
*/
private $newFilePath;
public function __construct(\Rector\Core\ValueObject\Application\File $file, string $newFilePath)
{
$this->file = $file;
$this->newFilePath = $newFilePath;
}
public function getFile() : \Rector\Core\ValueObject\Application\File
{
return $this->file;
}
public function getNewFilePath() : string
{
return $this->newFilePath;
}
/**
* @return Stmt[]
*/
public function getNodes() : array
{
return $this->file->getNewStmts();
}
public function getFilePath() : string
{
return $this->file->getFilePath();
}
}

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitdc63d1d77983e59462b2fefb99369e9f::getLoader();
return ComposerAutoloaderInit4c19a11cec9502c9c4467a6cbcd5d90c::getLoader();

View File

@ -1541,7 +1541,6 @@ return array(
'Rector\\Core\\ValueObjectFactory\\Application\\FileFactory' => $baseDir . '/src/ValueObjectFactory/Application/FileFactory.php',
'Rector\\Core\\ValueObjectFactory\\ProcessResultFactory' => $baseDir . '/src/ValueObjectFactory/ProcessResultFactory.php',
'Rector\\Core\\ValueObject\\Application\\File' => $baseDir . '/src/ValueObject/Application/File.php',
'Rector\\Core\\ValueObject\\Application\\MovedFile' => $baseDir . '/src/ValueObject/Application/MovedFile.php',
'Rector\\Core\\ValueObject\\Bootstrap\\BootstrapConfigs' => $baseDir . '/src/ValueObject/Bootstrap/BootstrapConfigs.php',
'Rector\\Core\\ValueObject\\Configuration' => $baseDir . '/src/ValueObject/Configuration.php',
'Rector\\Core\\ValueObject\\Error\\SystemError' => $baseDir . '/src/ValueObject/Error/SystemError.php',
@ -2447,7 +2446,6 @@ return array(
'Rector\\Renaming\\ValueObject\\RenameStaticMethod' => $baseDir . '/rules/Renaming/ValueObject/RenameStaticMethod.php',
'Rector\\Renaming\\ValueObject\\RenamedNamespace' => $baseDir . '/rules/Renaming/ValueObject/RenamedNamespace.php',
'Rector\\Restoration\\Rector\\ClassConstFetch\\MissingClassConstantReferenceToStringRector' => $baseDir . '/rules/Restoration/Rector/ClassConstFetch/MissingClassConstantReferenceToStringRector.php',
'Rector\\Restoration\\Rector\\ClassLike\\UpdateFileNameByClassNameFileSystemRector' => $baseDir . '/rules/Restoration/Rector/ClassLike/UpdateFileNameByClassNameFileSystemRector.php',
'Rector\\Restoration\\Rector\\Property\\MakeTypedPropertyNullableIfCheckedRector' => $baseDir . '/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php',
'Rector\\Set\\Contract\\SetListInterface' => $baseDir . '/packages/Set/Contract/SetListInterface.php',
'Rector\\Set\\ValueObject\\DowngradeLevelSetList' => $vendorDir . '/rector/rector-downgrade-php/src/Set/ValueObject/DowngradeLevelSetList.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitdc63d1d77983e59462b2fefb99369e9f
class ComposerAutoloaderInit4c19a11cec9502c9c4467a6cbcd5d90c
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitdc63d1d77983e59462b2fefb99369e9f
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitdc63d1d77983e59462b2fefb99369e9f', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit4c19a11cec9502c9c4467a6cbcd5d90c', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitdc63d1d77983e59462b2fefb99369e9f', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit4c19a11cec9502c9c4467a6cbcd5d90c', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit4c19a11cec9502c9c4467a6cbcd5d90c::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit4c19a11cec9502c9c4467a6cbcd5d90c::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f
class ComposerStaticInit4c19a11cec9502c9c4467a6cbcd5d90c
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1783,7 +1783,6 @@ class ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f
'Rector\\Core\\ValueObjectFactory\\Application\\FileFactory' => __DIR__ . '/../..' . '/src/ValueObjectFactory/Application/FileFactory.php',
'Rector\\Core\\ValueObjectFactory\\ProcessResultFactory' => __DIR__ . '/../..' . '/src/ValueObjectFactory/ProcessResultFactory.php',
'Rector\\Core\\ValueObject\\Application\\File' => __DIR__ . '/../..' . '/src/ValueObject/Application/File.php',
'Rector\\Core\\ValueObject\\Application\\MovedFile' => __DIR__ . '/../..' . '/src/ValueObject/Application/MovedFile.php',
'Rector\\Core\\ValueObject\\Bootstrap\\BootstrapConfigs' => __DIR__ . '/../..' . '/src/ValueObject/Bootstrap/BootstrapConfigs.php',
'Rector\\Core\\ValueObject\\Configuration' => __DIR__ . '/../..' . '/src/ValueObject/Configuration.php',
'Rector\\Core\\ValueObject\\Error\\SystemError' => __DIR__ . '/../..' . '/src/ValueObject/Error/SystemError.php',
@ -2689,7 +2688,6 @@ class ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f
'Rector\\Renaming\\ValueObject\\RenameStaticMethod' => __DIR__ . '/../..' . '/rules/Renaming/ValueObject/RenameStaticMethod.php',
'Rector\\Renaming\\ValueObject\\RenamedNamespace' => __DIR__ . '/../..' . '/rules/Renaming/ValueObject/RenamedNamespace.php',
'Rector\\Restoration\\Rector\\ClassConstFetch\\MissingClassConstantReferenceToStringRector' => __DIR__ . '/../..' . '/rules/Restoration/Rector/ClassConstFetch/MissingClassConstantReferenceToStringRector.php',
'Rector\\Restoration\\Rector\\ClassLike\\UpdateFileNameByClassNameFileSystemRector' => __DIR__ . '/../..' . '/rules/Restoration/Rector/ClassLike/UpdateFileNameByClassNameFileSystemRector.php',
'Rector\\Restoration\\Rector\\Property\\MakeTypedPropertyNullableIfCheckedRector' => __DIR__ . '/../..' . '/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php',
'Rector\\Set\\Contract\\SetListInterface' => __DIR__ . '/../..' . '/packages/Set/Contract/SetListInterface.php',
'Rector\\Set\\ValueObject\\DowngradeLevelSetList' => __DIR__ . '/..' . '/rector/rector-downgrade-php/src/Set/ValueObject/DowngradeLevelSetList.php',
@ -3109,9 +3107,9 @@ class ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit4c19a11cec9502c9c4467a6cbcd5d90c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit4c19a11cec9502c9c4467a6cbcd5d90c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit4c19a11cec9502c9c4467a6cbcd5d90c::$classMap;
}, null, ClassLoader::class);
}