mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-10 21:22:21 +00:00
Updated Rector to commit 1659ca292848fc1722b4b084d9fd1625b21e69c9
1659ca2928
[DX] Deprecate NonPhpRectorInterface, the only rule and its file processor, to make Rector handle exlusively PHP (#4761)
This commit is contained in:
parent
d45a7ad902
commit
7bb4bad572
|
@ -43,10 +43,8 @@ use Rector\Core\Console\Output\OutputFormatterCollector;
|
|||
use Rector\Core\Console\Style\RectorStyle;
|
||||
use Rector\Core\Console\Style\SymfonyStyleFactory;
|
||||
use Rector\Core\Contract\Processor\FileProcessorInterface;
|
||||
use Rector\Core\Contract\Rector\NonPhpRectorInterface;
|
||||
use Rector\Core\Contract\Rector\PhpRectorInterface;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\NonPhpFile\NonPhpFileProcessor;
|
||||
use Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser;
|
||||
use Rector\Core\ValueObjectFactory\Application\FileFactory;
|
||||
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
|
||||
|
@ -188,7 +186,6 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
$services->set(ConfigInitializer::class)->arg('$rectors', tagged_iterator(RectorInterface::class));
|
||||
$services->set(ListRulesCommand::class)->arg('$rectors', tagged_iterator(RectorInterface::class));
|
||||
$services->set(OutputFormatterCollector::class)->arg('$outputFormatters', tagged_iterator(OutputFormatterInterface::class));
|
||||
$services->set(NonPhpFileProcessor::class)->arg('$nonPhpRectors', tagged_iterator(NonPhpRectorInterface::class));
|
||||
$services->set(RectorNodeTraverser::class)->arg('$phpRectors', tagged_iterator(PhpRectorInterface::class));
|
||||
$services->set(NodeNameResolver::class)->arg('$nodeNameResolvers', tagged_iterator(NodeNameResolverInterface::class));
|
||||
$services->set(ApplicationFileProcessor::class)->arg('$fileProcessors', tagged_iterator(FileProcessorInterface::class));
|
||||
|
|
|
@ -32,10 +32,6 @@ final class FileDiffFactory
|
|||
$this->consoleDiffer = $consoleDiffer;
|
||||
$this->filePathHelper = $filePathHelper;
|
||||
}
|
||||
public function createFileDiff(File $file, string $oldContent, string $newContent) : FileDiff
|
||||
{
|
||||
return $this->createFileDiffWithLineChanges($file, $oldContent, $newContent, $file->getRectorWithLineChanges());
|
||||
}
|
||||
/**
|
||||
* @param RectorWithLineChange[] $rectorsWithLineChanges
|
||||
*/
|
||||
|
|
|
@ -224,7 +224,7 @@ final class LazyRectorConfig extends Container
|
|||
return \array_unique($duplicates);
|
||||
}
|
||||
/**
|
||||
* @param class-string<RectorInterface|PhpRectorInterface|NonPhpRectorInterface> $rectorClass
|
||||
* @param class-string<RectorInterface|PhpRectorInterface> $rectorClass
|
||||
*/
|
||||
private function tagRectorService(string $rectorClass) : void
|
||||
{
|
||||
|
@ -232,7 +232,8 @@ final class LazyRectorConfig extends Container
|
|||
if (\is_a($rectorClass, PhpRectorInterface::class, \true)) {
|
||||
$this->tag($rectorClass, PhpRectorInterface::class);
|
||||
} elseif (\is_a($rectorClass, NonPhpRectorInterface::class, \true)) {
|
||||
$this->tag($rectorClass, NonPhpRectorInterface::class);
|
||||
\trigger_error(\sprintf('The "%s" interface of "%s" rule is deprecated. Rector will only PHP code, as designed to with AST. For another file format, use custom tooling.', NonPhpRectorInterface::class, $rectorClass));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -269,7 +269,7 @@ final class RectorConfig extends ContainerConfigurator
|
|||
return $this->servicesConfigurator;
|
||||
}
|
||||
/**
|
||||
* @param class-string<RectorInterface|PhpRectorInterface|NonPhpRectorInterface> $rectorClass
|
||||
* @param class-string<RectorInterface|PhpRectorInterface> $rectorClass
|
||||
*/
|
||||
private function tagRectorService(ServiceConfigurator $rectorServiceConfigurator, string $rectorClass) : void
|
||||
{
|
||||
|
@ -277,7 +277,8 @@ final class RectorConfig extends ContainerConfigurator
|
|||
if (\is_a($rectorClass, PhpRectorInterface::class, \true)) {
|
||||
$rectorServiceConfigurator->tag(PhpRectorInterface::class);
|
||||
} elseif (\is_a($rectorClass, NonPhpRectorInterface::class, \true)) {
|
||||
$rectorServiceConfigurator->tag(NonPhpRectorInterface::class);
|
||||
\trigger_error(\sprintf('The "%s" interface of "%s" rule is deprecated. Rector will only PHP code, as designed to with AST. For another file format, use custom tooling.', NonPhpRectorInterface::class, $rectorClass));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ use PhpParser\NodeTraverser;
|
|||
use Rector\Core\Logging\CurrentRectorProvider;
|
||||
use Rector\Core\Provider\CurrentFileProvider;
|
||||
use Rector\Core\ValueObject\Application\File;
|
||||
use Rector\PostRector\Contract\Rector\PostRectorDependencyInterface;
|
||||
use Rector\PostRector\Contract\Rector\PostRectorInterface;
|
||||
use Rector\PostRector\Rector\ClassRenamingPostRector;
|
||||
use Rector\PostRector\Rector\NameImportingPostRector;
|
||||
use Rector\PostRector\Rector\UnusedImportRemovingPostRector;
|
||||
use Rector\PostRector\Rector\UseAddingPostRector;
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Rector\Skipper\Skipper\Skipper;
|
||||
final class PostFileProcessor
|
||||
{
|
||||
|
@ -88,14 +88,7 @@ final class PostFileProcessor
|
|||
if ($this->skipper->shouldSkipElementAndFilePath($postRector, $filePath)) {
|
||||
return \true;
|
||||
}
|
||||
if ($postRector instanceof PostRectorDependencyInterface) {
|
||||
$dependencies = $postRector->getRectorDependencies();
|
||||
foreach ($dependencies as $dependency) {
|
||||
if ($this->skipper->shouldSkipElementAndFilePath($dependency, $filePath)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
// skip renaming if rename class rector is skipped
|
||||
return $postRector instanceof ClassRenamingPostRector && $this->skipper->shouldSkipElementAndFilePath(RenameClassRector::class, $filePath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PostRector\Contract\Rector;
|
||||
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
interface PostRectorDependencyInterface
|
||||
{
|
||||
/**
|
||||
* @return class-string<RectorInterface>[]
|
||||
*/
|
||||
public function getRectorDependencies() : array;
|
||||
}
|
|
@ -14,16 +14,12 @@ use Rector\CodingStyle\Application\UseImportsRemover;
|
|||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
|
||||
use Rector\Core\Configuration\RenamedClassesDataCollector;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\NonPhpFile\Rector\RenameClassNonPhpRector;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PostRector\Contract\Rector\PostRectorDependencyInterface;
|
||||
use Rector\Renaming\NodeManipulator\ClassRenamer;
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPostRector implements PostRectorDependencyInterface
|
||||
final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPostRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -66,13 +62,6 @@ final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPo
|
|||
}
|
||||
return $nodes;
|
||||
}
|
||||
/**
|
||||
* @return class-string<RectorInterface>[]
|
||||
*/
|
||||
public function getRectorDependencies() : array
|
||||
{
|
||||
return [RenameClassRector::class, RenameClassNonPhpRector::class];
|
||||
}
|
||||
public function enterNode(Node $node) : ?Node
|
||||
{
|
||||
// cannot be renamed
|
||||
|
|
|
@ -5,7 +5,6 @@ namespace Rector\Testing\PHPUnit;
|
|||
|
||||
use RectorPrefix202308\Illuminate\Container\Container;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\Core\Contract\Rector\NonPhpRectorInterface;
|
||||
use Rector\Core\Contract\Rector\PhpRectorInterface;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\DependencyInjection\LazyContainerFactory;
|
||||
|
@ -64,7 +63,6 @@ abstract class AbstractLazyTestCase extends TestCase
|
|||
$privatesAccessor->propertyClosure($container, 'tags', static function (array $tags) : array {
|
||||
unset($tags[RectorInterface::class]);
|
||||
unset($tags[PhpRectorInterface::class]);
|
||||
unset($tags[NonPhpRectorInterface::class]);
|
||||
return $tags;
|
||||
});
|
||||
$rectors = $container->tagged(RectorInterface::class);
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'cbe3255f7e6b66af6c979131e200e7c01b4a0971';
|
||||
public const PACKAGE_VERSION = '1659ca292848fc1722b4b084d9fd1625b21e69c9';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-08-10 20:40:27';
|
||||
public const RELEASE_DATE = '2023-08-10 20:22:44';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -7,6 +7,9 @@ use Rector\Core\ValueObject\Application\File;
|
|||
use Rector\Core\ValueObject\Configuration;
|
||||
use Rector\Core\ValueObject\Error\SystemError;
|
||||
use Rector\Core\ValueObject\Reporting\FileDiff;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface FileProcessorInterface
|
||||
{
|
||||
public function supports(File $file, Configuration $configuration) : bool;
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Core\Contract\Rector;
|
||||
|
||||
/**
|
||||
* @deprecated Rector should never handle anything outside PHP files, as oustide it's scope - use custom tool instead.
|
||||
*/
|
||||
interface NonPhpRectorInterface extends \Rector\Core\Contract\Rector\RectorInterface
|
||||
{
|
||||
public function refactorFileContent(string $fileContent) : string;
|
||||
|
|
|
@ -55,13 +55,11 @@ use Rector\Core\Console\Output\OutputFormatterCollector;
|
|||
use Rector\Core\Console\Style\RectorStyle;
|
||||
use Rector\Core\Console\Style\SymfonyStyleFactory;
|
||||
use Rector\Core\Contract\Processor\FileProcessorInterface;
|
||||
use Rector\Core\Contract\Rector\NonPhpRectorInterface;
|
||||
use Rector\Core\Contract\Rector\PhpRectorInterface;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\Logging\CurrentRectorProvider;
|
||||
use Rector\Core\Logging\RectorOutput;
|
||||
use Rector\Core\NodeDecorator\CreatedByRuleDecorator;
|
||||
use Rector\Core\NonPhpFile\NonPhpFileProcessor;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
|
@ -276,7 +274,6 @@ final class LazyContainerFactory
|
|||
$lazyRectorConfig->singleton(ConsoleApplication::class, ConsoleApplication::class);
|
||||
$lazyRectorConfig->when(ConsoleApplication::class)->needs('$commands')->giveTagged(Command::class);
|
||||
$lazyRectorConfig->tag(PhpFileProcessor::class, FileProcessorInterface::class);
|
||||
$lazyRectorConfig->tag(NonPhpFileProcessor::class, FileProcessorInterface::class);
|
||||
$lazyRectorConfig->tag(ProcessCommand::class, Command::class);
|
||||
$lazyRectorConfig->tag(WorkerCommand::class, Command::class);
|
||||
$lazyRectorConfig->tag(SetupCICommand::class, Command::class);
|
||||
|
@ -285,7 +282,6 @@ final class LazyContainerFactory
|
|||
// dev
|
||||
$lazyRectorConfig->tag(MissingInSetCommand::class, Command::class);
|
||||
$lazyRectorConfig->tag(OutsideAnySetCommand::class, Command::class);
|
||||
$lazyRectorConfig->when(NonPhpFileProcessor::class)->needs('$nonPhpRectors')->giveTagged(NonPhpRectorInterface::class);
|
||||
$lazyRectorConfig->when(ApplicationFileProcessor::class)->needs('$fileProcessors')->giveTagged(FileProcessorInterface::class);
|
||||
$lazyRectorConfig->when(FileFactory::class)->needs('$fileProcessors')->giveTagged(FileProcessorInterface::class);
|
||||
$lazyRectorConfig->when(RectorNodeTraverser::class)->needs('$phpRectors')->giveTagged(PhpRectorInterface::class);
|
||||
|
|
|
@ -9,7 +9,6 @@ use Rector\ChangesReporting\Contract\Output\OutputFormatterInterface;
|
|||
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
|
||||
use Rector\Core\Config\Loader\ConfigureCallMergingLoaderFactory;
|
||||
use Rector\Core\Contract\Processor\FileProcessorInterface;
|
||||
use Rector\Core\Contract\Rector\NonPhpRectorInterface;
|
||||
use Rector\Core\Contract\Rector\PhpRectorInterface;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
|
||||
|
@ -33,7 +32,7 @@ final class ContainerBuilderFactory
|
|||
/**
|
||||
* @var array<class-string>
|
||||
*/
|
||||
private const TYPES_TO_TAG_AUTOCONFIGURE = [BasePhpDocNodeVisitorInterface::class, PhpDocNodeDecoratorInterface::class, NodeTypeResolverInterface::class, ScopeResolverNodeVisitorInterface::class, TypeMapperInterface::class, PhpParserNodeMapperInterface::class, PhpDocTypeMapperInterface::class, ClassNameImportSkipVoterInterface::class, RectorInterface::class, Command::class, RectorInterface::class, OutputFormatterInterface::class, NonPhpRectorInterface::class, PhpRectorInterface::class, NodeNameResolverInterface::class, FileProcessorInterface::class, AnnotationToAttributeMapperInterface::class];
|
||||
private const TYPES_TO_TAG_AUTOCONFIGURE = [BasePhpDocNodeVisitorInterface::class, PhpDocNodeDecoratorInterface::class, NodeTypeResolverInterface::class, ScopeResolverNodeVisitorInterface::class, TypeMapperInterface::class, PhpParserNodeMapperInterface::class, PhpDocTypeMapperInterface::class, ClassNameImportSkipVoterInterface::class, RectorInterface::class, Command::class, RectorInterface::class, OutputFormatterInterface::class, PhpRectorInterface::class, NodeNameResolverInterface::class, FileProcessorInterface::class, AnnotationToAttributeMapperInterface::class];
|
||||
public function __construct(ConfigureCallMergingLoaderFactory $configureCallMergingLoaderFactory)
|
||||
{
|
||||
$this->configureCallMergingLoaderFactory = $configureCallMergingLoaderFactory;
|
||||
|
|
|
@ -1,107 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\NonPhpFile;
|
||||
|
||||
use Rector\Caching\Detector\ChangedFilesDetector;
|
||||
use Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory;
|
||||
use Rector\Core\Contract\Processor\FileProcessorInterface;
|
||||
use Rector\Core\Contract\Rector\NonPhpRectorInterface;
|
||||
use Rector\Core\ValueObject\Application\File;
|
||||
use Rector\Core\ValueObject\Configuration;
|
||||
use Rector\Core\ValueObject\Error\SystemError;
|
||||
use Rector\Core\ValueObject\Reporting\FileDiff;
|
||||
use Rector\Parallel\ValueObject\Bridge;
|
||||
use RectorPrefix202308\Symfony\Component\Filesystem\Filesystem;
|
||||
final class NonPhpFileProcessor implements FileProcessorInterface
|
||||
{
|
||||
/**
|
||||
* @var NonPhpRectorInterface[]
|
||||
* @readonly
|
||||
*/
|
||||
private $nonPhpRectors;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory
|
||||
*/
|
||||
private $fileDiffFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Caching\Detector\ChangedFilesDetector
|
||||
*/
|
||||
private $changedFilesDetector;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Symfony\Component\Filesystem\Filesystem
|
||||
*/
|
||||
private $filesystem;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private const SUFFIXES = ['neon', 'yaml', 'xml', 'yml', 'twig', 'latte', 'blade.php', 'tpl'];
|
||||
/**
|
||||
* @param NonPhpRectorInterface[] $nonPhpRectors
|
||||
*/
|
||||
public function __construct(iterable $nonPhpRectors, FileDiffFactory $fileDiffFactory, ChangedFilesDetector $changedFilesDetector, Filesystem $filesystem)
|
||||
{
|
||||
$this->nonPhpRectors = $nonPhpRectors;
|
||||
$this->fileDiffFactory = $fileDiffFactory;
|
||||
$this->changedFilesDetector = $changedFilesDetector;
|
||||
$this->filesystem = $filesystem;
|
||||
}
|
||||
/**
|
||||
* @return array{system_errors: SystemError[], file_diffs: FileDiff[]}
|
||||
*/
|
||||
public function process(File $file, Configuration $configuration) : array
|
||||
{
|
||||
$systemErrorsAndFileDiffs = [Bridge::SYSTEM_ERRORS => [], Bridge::FILE_DIFFS => []];
|
||||
if ($this->nonPhpRectors === []) {
|
||||
return $systemErrorsAndFileDiffs;
|
||||
}
|
||||
$oldFileContent = $file->getFileContent();
|
||||
$newFileContent = $file->getFileContent();
|
||||
foreach ($this->nonPhpRectors as $nonPhpRector) {
|
||||
$newFileContent = $nonPhpRector->refactorFileContent($file->getFileContent());
|
||||
if ($oldFileContent === $newFileContent) {
|
||||
continue;
|
||||
}
|
||||
$file->changeFileContent($newFileContent);
|
||||
}
|
||||
if ($oldFileContent !== $newFileContent) {
|
||||
$fileDiff = $this->fileDiffFactory->createFileDiff($file, $oldFileContent, $newFileContent);
|
||||
$systemErrorsAndFileDiffs[Bridge::FILE_DIFFS][] = $fileDiff;
|
||||
$this->printFile($file, $configuration);
|
||||
} else {
|
||||
$this->changedFilesDetector->addCachableFile($file->getFilePath());
|
||||
}
|
||||
return $systemErrorsAndFileDiffs;
|
||||
}
|
||||
public function supports(File $file, Configuration $configuration) : bool
|
||||
{
|
||||
// early assign to variable for increase performance
|
||||
// @see https://3v4l.org/FM3vY#focus=8.0.7 vs https://3v4l.org/JZW7b#focus=8.0.7
|
||||
$filePath = $file->getFilePath();
|
||||
// bug in path extension
|
||||
foreach ($this->getSupportedFileExtensions() as $fileExtension) {
|
||||
if (\substr_compare($filePath, '.' . $fileExtension, -\strlen('.' . $fileExtension)) === 0) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSupportedFileExtensions() : array
|
||||
{
|
||||
return self::SUFFIXES;
|
||||
}
|
||||
private function printFile(File $file, Configuration $configuration) : void
|
||||
{
|
||||
if ($configuration->isDryRun()) {
|
||||
return;
|
||||
}
|
||||
$filePath = $file->getFilePath();
|
||||
$this->filesystem->dumpFile($filePath, $file->getFileContent());
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\NonPhpFile\Rector;
|
||||
|
||||
use RectorPrefix202308\Nette\Utils\Strings;
|
||||
use Rector\Core\Configuration\RenamedClassesDataCollector;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\NonPhpRectorInterface;
|
||||
use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202308\Webmozart\Assert\Assert;
|
||||
final class RenameClassNonPhpRector implements NonPhpRectorInterface, ConfigurableRuleInterface, ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Configuration\RenamedClassesDataCollector
|
||||
*/
|
||||
private $renamedClassesDataCollector;
|
||||
/**
|
||||
* @see https://regex101.com/r/HKUFJD/7
|
||||
* for "?<!" @see https://stackoverflow.com/a/3735908/1348344
|
||||
* @var string
|
||||
*/
|
||||
private const STANDALONE_CLASS_PREFIX_REGEX = '#((?<!(\\\\|"|\\>|\\.|\'))|(?<extra_space>\\s+\\\\))';
|
||||
/**
|
||||
* @see https://regex101.com/r/HKUFJD/5
|
||||
* @see https://stackoverflow.com/a/3926546/1348344
|
||||
* @var string
|
||||
*/
|
||||
private const STANDALONE_CLASS_SUFFIX_REGEX = '(?=::)#';
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private $renameClasses = [];
|
||||
public function __construct(RenamedClassesDataCollector $renamedClassesDataCollector)
|
||||
{
|
||||
$this->renamedClassesDataCollector = $renamedClassesDataCollector;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change class names and just renamed classes in non-PHP files, NEON, YAML, TWIG, LATTE, blade etc. mostly with regular expressions', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
services:
|
||||
- SomeOldClass
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
services:
|
||||
- SomeNewClass
|
||||
CODE_SAMPLE
|
||||
, ['SomeOldClass' => 'SomeNewClass'])]);
|
||||
}
|
||||
public function refactorFileContent(string $fileContent) : string
|
||||
{
|
||||
$classRenames = $this->getRenameClasses();
|
||||
return $this->renameClasses($fileContent, $classRenames);
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
$renameClasses = $configuration;
|
||||
Assert::allString(\array_keys($renameClasses));
|
||||
Assert::allString($renameClasses);
|
||||
$this->renameClasses = $renameClasses;
|
||||
}
|
||||
/**
|
||||
* @param array<string, string> $classRenames
|
||||
*/
|
||||
private function renameClasses(string $newContent, array $classRenames) : string
|
||||
{
|
||||
$classRenames = $this->addDoubleSlashed($classRenames);
|
||||
foreach ($classRenames as $oldClass => $newClass) {
|
||||
// the old class is without slashes, it can make mess as similar to a word in the text, so we have to be more strict about it
|
||||
$oldClassRegex = $this->createOldClassRegex($oldClass);
|
||||
$newContent = Strings::replace($newContent, $oldClassRegex, static function (array $match) use($newClass) : string {
|
||||
return ($match['extra_space'] ?? '') . $newClass;
|
||||
});
|
||||
}
|
||||
return $newContent;
|
||||
}
|
||||
/**
|
||||
* Process with double quotes too, e.g. in twig
|
||||
*
|
||||
* @param array<string, string> $classRenames
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function addDoubleSlashed(array $classRenames) : array
|
||||
{
|
||||
foreach ($classRenames as $oldClass => $newClass) {
|
||||
// to prevent no slash override
|
||||
if (\strpos($oldClass, '\\') === \false) {
|
||||
continue;
|
||||
}
|
||||
$doubleSlashOldClass = \str_replace('\\', '\\\\', $oldClass);
|
||||
$doubleSlashNewClass = \str_replace('\\', '\\\\', $newClass);
|
||||
$classRenames[$doubleSlashOldClass] = $doubleSlashNewClass;
|
||||
}
|
||||
return $classRenames;
|
||||
}
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getRenameClasses() : array
|
||||
{
|
||||
/** @var array<string, string> $renameClasses */
|
||||
$renameClasses = \array_merge($this->renameClasses, $this->renamedClassesDataCollector->getOldToNewClasses());
|
||||
return $renameClasses;
|
||||
}
|
||||
private function createOldClassRegex(string $oldClass) : string
|
||||
{
|
||||
if (\strpos($oldClass, '\\') === \false) {
|
||||
return self::STANDALONE_CLASS_PREFIX_REGEX . \preg_quote($oldClass, '#') . self::STANDALONE_CLASS_SUFFIX_REGEX;
|
||||
}
|
||||
return '#' . \preg_quote($oldClass, '#') . '#';
|
||||
}
|
||||
}
|
|
@ -3,10 +3,10 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Core\Reflection;
|
||||
|
||||
use ReflectionEnum;
|
||||
use PHPStan\BetterReflection\Reflection\ReflectionClass;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\Core\Util\Reflection\PrivatesAccessor;
|
||||
use PHPStan\BetterReflection\Reflection\ReflectionClass;
|
||||
use ReflectionEnum;
|
||||
final class ClassReflectionAnalyzer
|
||||
{
|
||||
/**
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInite95326904e6f6eeea7178ffc963954b8::getLoader();
|
||||
return ComposerAutoloaderInitcda04089830bd931ef1039b6cb51d8fc::getLoader();
|
||||
|
|
3
vendor/composer/autoload_classmap.php
vendored
3
vendor/composer/autoload_classmap.php
vendored
|
@ -1579,8 +1579,6 @@ return array(
|
|||
'Rector\\Core\\NodeManipulator\\PropertyFetchAssignManipulator' => $baseDir . '/src/NodeManipulator/PropertyFetchAssignManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\PropertyManipulator' => $baseDir . '/src/NodeManipulator/PropertyManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\StmtsManipulator' => $baseDir . '/src/NodeManipulator/StmtsManipulator.php',
|
||||
'Rector\\Core\\NonPhpFile\\NonPhpFileProcessor' => $baseDir . '/src/NonPhpFile/NonPhpFileProcessor.php',
|
||||
'Rector\\Core\\NonPhpFile\\Rector\\RenameClassNonPhpRector' => $baseDir . '/src/NonPhpFile/Rector/RenameClassNonPhpRector.php',
|
||||
'Rector\\Core\\PHPStan\\NodeVisitor\\UnreachableStatementNodeVisitor' => $baseDir . '/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php',
|
||||
'Rector\\Core\\PHPStan\\NodeVisitor\\WrappedNodeRestoringNodeVisitor' => $baseDir . '/src/PHPStan/NodeVisitor/WrappedNodeRestoringNodeVisitor.php',
|
||||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\ClosureTypeToCallReflectionResolver' => $baseDir . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php',
|
||||
|
@ -2287,7 +2285,6 @@ return array(
|
|||
'Rector\\PostRector\\Application\\PostFileProcessor' => $baseDir . '/packages/PostRector/Application/PostFileProcessor.php',
|
||||
'Rector\\PostRector\\Collector\\UseNodesToAddCollector' => $baseDir . '/packages/PostRector/Collector/UseNodesToAddCollector.php',
|
||||
'Rector\\PostRector\\Contract\\Collector\\NodeCollectorInterface' => $baseDir . '/packages/PostRector/Contract/Collector/NodeCollectorInterface.php',
|
||||
'Rector\\PostRector\\Contract\\Rector\\PostRectorDependencyInterface' => $baseDir . '/packages/PostRector/Contract/Rector/PostRectorDependencyInterface.php',
|
||||
'Rector\\PostRector\\Contract\\Rector\\PostRectorInterface' => $baseDir . '/packages/PostRector/Contract/Rector/PostRectorInterface.php',
|
||||
'Rector\\PostRector\\Rector\\AbstractPostRector' => $baseDir . '/packages/PostRector/Rector/AbstractPostRector.php',
|
||||
'Rector\\PostRector\\Rector\\ClassRenamingPostRector' => $baseDir . '/packages/PostRector/Rector/ClassRenamingPostRector.php',
|
||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInite95326904e6f6eeea7178ffc963954b8
|
||||
class ComposerAutoloaderInitcda04089830bd931ef1039b6cb51d8fc
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInite95326904e6f6eeea7178ffc963954b8
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInite95326904e6f6eeea7178ffc963954b8', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitcda04089830bd931ef1039b6cb51d8fc', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite95326904e6f6eeea7178ffc963954b8', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitcda04089830bd931ef1039b6cb51d8fc', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite95326904e6f6eeea7178ffc963954b8::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitcda04089830bd931ef1039b6cb51d8fc::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInite95326904e6f6eeea7178ffc963954b8::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitcda04089830bd931ef1039b6cb51d8fc::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
11
vendor/composer/autoload_static.php
vendored
11
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInite95326904e6f6eeea7178ffc963954b8
|
||||
class ComposerStaticInitcda04089830bd931ef1039b6cb51d8fc
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -1832,8 +1832,6 @@ class ComposerStaticInite95326904e6f6eeea7178ffc963954b8
|
|||
'Rector\\Core\\NodeManipulator\\PropertyFetchAssignManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/PropertyFetchAssignManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\PropertyManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/PropertyManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\StmtsManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/StmtsManipulator.php',
|
||||
'Rector\\Core\\NonPhpFile\\NonPhpFileProcessor' => __DIR__ . '/../..' . '/src/NonPhpFile/NonPhpFileProcessor.php',
|
||||
'Rector\\Core\\NonPhpFile\\Rector\\RenameClassNonPhpRector' => __DIR__ . '/../..' . '/src/NonPhpFile/Rector/RenameClassNonPhpRector.php',
|
||||
'Rector\\Core\\PHPStan\\NodeVisitor\\UnreachableStatementNodeVisitor' => __DIR__ . '/../..' . '/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php',
|
||||
'Rector\\Core\\PHPStan\\NodeVisitor\\WrappedNodeRestoringNodeVisitor' => __DIR__ . '/../..' . '/src/PHPStan/NodeVisitor/WrappedNodeRestoringNodeVisitor.php',
|
||||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\ClosureTypeToCallReflectionResolver' => __DIR__ . '/../..' . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php',
|
||||
|
@ -2540,7 +2538,6 @@ class ComposerStaticInite95326904e6f6eeea7178ffc963954b8
|
|||
'Rector\\PostRector\\Application\\PostFileProcessor' => __DIR__ . '/../..' . '/packages/PostRector/Application/PostFileProcessor.php',
|
||||
'Rector\\PostRector\\Collector\\UseNodesToAddCollector' => __DIR__ . '/../..' . '/packages/PostRector/Collector/UseNodesToAddCollector.php',
|
||||
'Rector\\PostRector\\Contract\\Collector\\NodeCollectorInterface' => __DIR__ . '/../..' . '/packages/PostRector/Contract/Collector/NodeCollectorInterface.php',
|
||||
'Rector\\PostRector\\Contract\\Rector\\PostRectorDependencyInterface' => __DIR__ . '/../..' . '/packages/PostRector/Contract/Rector/PostRectorDependencyInterface.php',
|
||||
'Rector\\PostRector\\Contract\\Rector\\PostRectorInterface' => __DIR__ . '/../..' . '/packages/PostRector/Contract/Rector/PostRectorInterface.php',
|
||||
'Rector\\PostRector\\Rector\\AbstractPostRector' => __DIR__ . '/../..' . '/packages/PostRector/Rector/AbstractPostRector.php',
|
||||
'Rector\\PostRector\\Rector\\ClassRenamingPostRector' => __DIR__ . '/../..' . '/packages/PostRector/Rector/ClassRenamingPostRector.php',
|
||||
|
@ -2985,9 +2982,9 @@ class ComposerStaticInite95326904e6f6eeea7178ffc963954b8
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite95326904e6f6eeea7178ffc963954b8::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite95326904e6f6eeea7178ffc963954b8::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite95326904e6f6eeea7178ffc963954b8::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitcda04089830bd931ef1039b6cb51d8fc::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitcda04089830bd931ef1039b6cb51d8fc::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitcda04089830bd931ef1039b6cb51d8fc::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
|
@ -2133,12 +2133,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "c6b7ee75239900ccf9abd234fc135e817f869d93"
|
||||
"reference": "ba9b9f4de0a26b2a331c359a6c4d293041d6a1c9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/c6b7ee75239900ccf9abd234fc135e817f869d93",
|
||||
"reference": "c6b7ee75239900ccf9abd234fc135e817f869d93",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/ba9b9f4de0a26b2a331c359a6c4d293041d6a1c9",
|
||||
"reference": "ba9b9f4de0a26b2a331c359a6c4d293041d6a1c9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2169,7 +2169,7 @@
|
|||
"tomasvotruba\/type-coverage": "^0.2",
|
||||
"tomasvotruba\/unused-public": "^0.2"
|
||||
},
|
||||
"time": "2023-08-10T09:36:28+00:00",
|
||||
"time": "2023-08-10T19:01:54+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
|||
*/
|
||||
final class GeneratedConfig
|
||||
{
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d09e0f3'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 44cec67'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 14f0412'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main c6b7ee7'));
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d09e0f3'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 44cec67'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 14f0412'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ba9b9f4'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -4,10 +4,8 @@ declare (strict_types=1);
|
|||
namespace RectorPrefix202308;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Core\NonPhpFile\Rector\RenameClassNonPhpRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$services = $rectorConfig->services();
|
||||
$services->defaults()->public()->autowire()->autoconfigure();
|
||||
$services->load('Rector\\Symfony\\', __DIR__ . '/../src')->exclude([__DIR__ . '/../src/Rector', __DIR__ . '/../src/ValueObject']);
|
||||
$rectorConfig->rule(RenameClassNonPhpRector::class);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user