Updated Rector to commit a4eff1e0ad

a4eff1e0ad [DX] Remove MoveServicesBySuffixToDirectoryRector, better handle by PHPStan + PHPStorm refacor (#1834)
This commit is contained in:
Tomas Votruba 2022-02-18 09:30:35 +00:00
parent 41ea630c4f
commit 2493da671a
10 changed files with 420 additions and 350 deletions

File diff suppressed because it is too large Load Diff

View File

@ -299,7 +299,10 @@ final class PhpDocInfo
$phpDocNodeTraverser = new \RectorPrefix20220218\Symplify\SimplePhpDocParser\PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($this->phpDocNode, '', function (\PHPStan\PhpDocParser\Ast\Node $node) use($typeToRemove) : ?int {
if ($node instanceof \PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode && \is_a($node->value, $typeToRemove, \true)) {
if (\strncmp($node->name, '@psalm-', \strlen('@psalm-')) === 0 || \strncmp($node->name, '@phpstan-', \strlen('@phpstan-')) === 0) {
if (\strncmp($node->name, '@psalm-', \strlen('@psalm-')) === 0) {
return null;
}
if (\strncmp($node->name, '@phpstan-', \strlen('@phpstan-')) === 0) {
return null;
}
$this->markAsChanged();

View File

@ -1,17 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Autodiscovery\FileLocation;
final class ExpectedFileLocationResolver
{
/**
* Resolves if is suffix in the same category, e.g. "Exception/SomeException.php"
*/
public function resolve(string $escapedGroupName, string $suffixPattern) : string
{
$escapedGroupName = \preg_quote($escapedGroupName, '#');
$escapedSuffixPattern = \preg_quote($suffixPattern, '#');
return \sprintf('#\\/%s\\/.+%s#', $escapedGroupName, $escapedSuffixPattern);
}
}

View File

@ -1,132 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Autodiscovery\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\Autodiscovery\FileLocation\ExpectedFileLocationResolver;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Util\StringUtils;
use Rector\Core\ValueObject\Application\File;
use Rector\FileSystemRector\ValueObject\AddedFileWithNodes;
use Rector\FileSystemRector\ValueObjectFactory\AddedFileWithNodesFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Symplify\SmartFileSystem\SmartFileInfo;
use RectorPrefix20220218\Webmozart\Assert\Assert;
/**
* Inspiration @see https://github.com/rectorphp/rector/pull/1865/files#diff-0d18e660cdb626958662641b491623f8
*
* @see \Rector\Tests\Autodiscovery\Rector\Class_\MoveServicesBySuffixToDirectoryRector\MoveServicesBySuffixToDirectoryRectorTest
*/
final class MoveServicesBySuffixToDirectoryRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\ConfigurableRectorInterface
{
/**
* @var string[]
*/
private $groupNamesBySuffix = [];
/**
* @readonly
* @var \Rector\Autodiscovery\FileLocation\ExpectedFileLocationResolver
*/
private $expectedFileLocationResolver;
/**
* @readonly
* @var \Rector\FileSystemRector\ValueObjectFactory\AddedFileWithNodesFactory
*/
private $addedFileWithNodesFactory;
public function __construct(\Rector\Autodiscovery\FileLocation\ExpectedFileLocationResolver $expectedFileLocationResolver, \Rector\FileSystemRector\ValueObjectFactory\AddedFileWithNodesFactory $addedFileWithNodesFactory)
{
$this->expectedFileLocationResolver = $expectedFileLocationResolver;
$this->addedFileWithNodesFactory = $addedFileWithNodesFactory;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Move classes by their suffix to their own group/directory', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE'
// file: app/Entity/ProductRepository.php
namespace App\Entity;
class ProductRepository
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
// file: app/Repository/ProductRepository.php
namespace App\Repository;
class ProductRepository
{
}
CODE_SAMPLE
, ['Repository'])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Stmt\Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
$this->processGroupNamesBySuffix($this->file->getSmartFileInfo(), $this->groupNamesBySuffix);
return null;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
\RectorPrefix20220218\Webmozart\Assert\Assert::allString($configuration);
$this->groupNamesBySuffix = $configuration;
}
/**
* A. Match classes by suffix and move them to group namespace
*
* E.g. "App\Controller\SomeException"
*
* "App\Exception\SomeException"
*
* @param string[] $groupNamesBySuffix
*/
private function processGroupNamesBySuffix(\Symplify\SmartFileSystem\SmartFileInfo $smartFileInfo, array $groupNamesBySuffix) : void
{
foreach ($groupNamesBySuffix as $groupNames) {
// has class suffix
$suffixPattern = '\\w+' . $groupNames . '(Test)?\\.php$';
if (!\Rector\Core\Util\StringUtils::isMatch($smartFileInfo->getRealPath(), '#' . $suffixPattern . '#')) {
continue;
}
if ($this->isLocatedInExpectedLocation($groupNames, $suffixPattern, $smartFileInfo)) {
continue;
}
// file is already in the group
if (\Rector\Core\Util\StringUtils::isMatch($smartFileInfo->getPath(), '#' . $groupNames . '$#')) {
continue;
}
$this->moveFileToGroupName($smartFileInfo, $this->file, $groupNames);
return;
}
}
private function isLocatedInExpectedLocation(string $groupName, string $suffixPattern, \Symplify\SmartFileSystem\SmartFileInfo $smartFileInfo) : bool
{
$expectedLocationFilePattern = $this->expectedFileLocationResolver->resolve($groupName, $suffixPattern);
return \Rector\Core\Util\StringUtils::isMatch($smartFileInfo->getRealPath(), $expectedLocationFilePattern);
}
private function moveFileToGroupName(\Symplify\SmartFileSystem\SmartFileInfo $fileInfo, \Rector\Core\ValueObject\Application\File $file, string $desiredGroupName) : void
{
$addedFileWithNodes = $this->addedFileWithNodesFactory->createWithDesiredGroup($fileInfo, $file, $desiredGroupName);
if (!$addedFileWithNodes instanceof \Rector\FileSystemRector\ValueObject\AddedFileWithNodes) {
return;
}
$this->removedAndAddedFilesCollector->removeFile($fileInfo);
$this->removedAndAddedFilesCollector->addAddedFile($addedFileWithNodes);
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '323be2a5deaa8aaf3c1cd2e3ba98ee73f34ed685';
public const PACKAGE_VERSION = 'a4eff1e0adc5dec582adeeeff55512f6805e0f43';
/**
* @var string
*/
public const RELEASE_DATE = '2022-02-18 08:56:08';
public const RELEASE_DATE = '2022-02-18 10:22:26';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220218\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit05f6df92e513c6794b7b107284782782::getLoader();
return ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac::getLoader();

View File

@ -1373,10 +1373,8 @@ return array(
'Rector\\Arguments\\ValueObject\\ReplaceFuncCallArgumentDefaultValue' => $baseDir . '/rules/Arguments/ValueObject/ReplaceFuncCallArgumentDefaultValue.php',
'Rector\\Arguments\\ValueObject\\SwapFuncCallArguments' => $baseDir . '/rules/Arguments/ValueObject/SwapFuncCallArguments.php',
'Rector\\Autodiscovery\\Configuration\\CategoryNamespaceProvider' => $baseDir . '/rules/Autodiscovery/Configuration/CategoryNamespaceProvider.php',
'Rector\\Autodiscovery\\FileLocation\\ExpectedFileLocationResolver' => $baseDir . '/rules/Autodiscovery/FileLocation/ExpectedFileLocationResolver.php',
'Rector\\Autodiscovery\\NodeAnalyzer\\NetteComponentFactoryInterfaceAnalyzer' => $baseDir . '/rules/Autodiscovery/NodeAnalyzer/NetteComponentFactoryInterfaceAnalyzer.php',
'Rector\\Autodiscovery\\Rector\\Class_\\MoveEntitiesToEntityDirectoryRector' => $baseDir . '/rules/Autodiscovery/Rector/Class_/MoveEntitiesToEntityDirectoryRector.php',
'Rector\\Autodiscovery\\Rector\\Class_\\MoveServicesBySuffixToDirectoryRector' => $baseDir . '/rules/Autodiscovery/Rector/Class_/MoveServicesBySuffixToDirectoryRector.php',
'Rector\\Autodiscovery\\Rector\\Interface_\\MoveInterfacesToContractNamespaceDirectoryRector' => $baseDir . '/rules/Autodiscovery/Rector/Interface_/MoveInterfacesToContractNamespaceDirectoryRector.php',
'Rector\\BetterPhpDocParser\\Annotation\\AnnotationNaming' => $baseDir . '/packages/BetterPhpDocParser/Annotation/AnnotationNaming.php',
'Rector\\BetterPhpDocParser\\Attributes\\AttributeMirrorer' => $baseDir . '/packages/BetterPhpDocParser/Attributes/AttributeMirrorer.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit05f6df92e513c6794b7b107284782782
class ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit05f6df92e513c6794b7b107284782782
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit05f6df92e513c6794b7b107284782782', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit05f6df92e513c6794b7b107284782782', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit05f6df92e513c6794b7b107284782782::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInit05f6df92e513c6794b7b107284782782
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit05f6df92e513c6794b7b107284782782::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire05f6df92e513c6794b7b107284782782($fileIdentifier, $file);
composerRequire3d41aaead61a4e9379fe1a73755481ac($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInit05f6df92e513c6794b7b107284782782
* @param string $file
* @return void
*/
function composerRequire05f6df92e513c6794b7b107284782782($fileIdentifier, $file)
function composerRequire3d41aaead61a4e9379fe1a73755481ac($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 ComposerStaticInit05f6df92e513c6794b7b107284782782
class ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -1762,10 +1762,8 @@ class ComposerStaticInit05f6df92e513c6794b7b107284782782
'Rector\\Arguments\\ValueObject\\ReplaceFuncCallArgumentDefaultValue' => __DIR__ . '/../..' . '/rules/Arguments/ValueObject/ReplaceFuncCallArgumentDefaultValue.php',
'Rector\\Arguments\\ValueObject\\SwapFuncCallArguments' => __DIR__ . '/../..' . '/rules/Arguments/ValueObject/SwapFuncCallArguments.php',
'Rector\\Autodiscovery\\Configuration\\CategoryNamespaceProvider' => __DIR__ . '/../..' . '/rules/Autodiscovery/Configuration/CategoryNamespaceProvider.php',
'Rector\\Autodiscovery\\FileLocation\\ExpectedFileLocationResolver' => __DIR__ . '/../..' . '/rules/Autodiscovery/FileLocation/ExpectedFileLocationResolver.php',
'Rector\\Autodiscovery\\NodeAnalyzer\\NetteComponentFactoryInterfaceAnalyzer' => __DIR__ . '/../..' . '/rules/Autodiscovery/NodeAnalyzer/NetteComponentFactoryInterfaceAnalyzer.php',
'Rector\\Autodiscovery\\Rector\\Class_\\MoveEntitiesToEntityDirectoryRector' => __DIR__ . '/../..' . '/rules/Autodiscovery/Rector/Class_/MoveEntitiesToEntityDirectoryRector.php',
'Rector\\Autodiscovery\\Rector\\Class_\\MoveServicesBySuffixToDirectoryRector' => __DIR__ . '/../..' . '/rules/Autodiscovery/Rector/Class_/MoveServicesBySuffixToDirectoryRector.php',
'Rector\\Autodiscovery\\Rector\\Interface_\\MoveInterfacesToContractNamespaceDirectoryRector' => __DIR__ . '/../..' . '/rules/Autodiscovery/Rector/Interface_/MoveInterfacesToContractNamespaceDirectoryRector.php',
'Rector\\BetterPhpDocParser\\Annotation\\AnnotationNaming' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Annotation/AnnotationNaming.php',
'Rector\\BetterPhpDocParser\\Attributes\\AttributeMirrorer' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Attributes/AttributeMirrorer.php',
@ -3871,9 +3869,9 @@ class ComposerStaticInit05f6df92e513c6794b7b107284782782
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit05f6df92e513c6794b7b107284782782::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit05f6df92e513c6794b7b107284782782::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit05f6df92e513c6794b7b107284782782::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220218\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit05f6df92e513c6794b7b107284782782', false) && !interface_exists('ComposerAutoloaderInit05f6df92e513c6794b7b107284782782', false) && !trait_exists('ComposerAutoloaderInit05f6df92e513c6794b7b107284782782', false)) {
spl_autoload_call('RectorPrefix20220218\ComposerAutoloaderInit05f6df92e513c6794b7b107284782782');
if (!class_exists('ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac', false) && !interface_exists('ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac', false) && !trait_exists('ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac', false)) {
spl_autoload_call('RectorPrefix20220218\ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20220218\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220218\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire05f6df92e513c6794b7b107284782782')) {
function composerRequire05f6df92e513c6794b7b107284782782() {
return \RectorPrefix20220218\composerRequire05f6df92e513c6794b7b107284782782(...func_get_args());
if (!function_exists('composerRequire3d41aaead61a4e9379fe1a73755481ac')) {
function composerRequire3d41aaead61a4e9379fe1a73755481ac() {
return \RectorPrefix20220218\composerRequire3d41aaead61a4e9379fe1a73755481ac(...func_get_args());
}
}
if (!function_exists('scanPath')) {