[DX] Remove CommandNaming magic, check rector class exists in RectorConfig (#2372)

This commit is contained in:
Tomas Votruba 2022-05-27 16:58:29 +02:00 committed by GitHub
parent 03da98750a
commit a9dd89b1cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 191 additions and 358 deletions

View File

@ -2,17 +2,59 @@
declare(strict_types=1); declare(strict_types=1);
use Composer\Semver\VersionParser;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\Rules\English\InflectorFactory;
use Ergebnis\Json\Printer\Printer;
use Ergebnis\Json\Printer\PrinterInterface;
use Idiosyncratic\EditorConfig\EditorConfig;
use OndraM\CiDetector\CiDetector; use OndraM\CiDetector\CiDetector;
use PhpParser\BuilderFactory;
use PhpParser\Lexer;
use PhpParser\NodeFinder;
use PhpParser\NodeVisitor\CloningVisitor;
use PhpParser\NodeVisitor\NodeConnectingVisitor;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\ScopeFactory;
use PHPStan\Dependency\DependencyResolver;
use PHPStan\File\FileHelper;
use PHPStan\Parser\Parser;
use PHPStan\PhpDoc\TypeNodeResolver;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\Reflection\ReflectionProvider;
use Rector\BetterPhpDocParser\PhpDocParser\BetterPhpDocParser;
use Rector\BetterPhpDocParser\PhpDocParser\BetterTypeParser;
use Rector\Caching\Cache;
use Rector\Caching\CacheFactory;
use Rector\Caching\ValueObject\Storage\MemoryCacheStorage; use Rector\Caching\ValueObject\Storage\MemoryCacheStorage;
use Rector\Config\RectorConfig; use Rector\Config\RectorConfig;
use Rector\Core\Bootstrap\ExtensionConfigResolver; use Rector\Core\Bootstrap\ExtensionConfigResolver;
use Rector\Core\Console\ConsoleApplication;
use Rector\Core\Console\Style\RectorConsoleOutputStyle;
use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory;
use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector;
use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
use Rector\PSR4\Composer\PSR4NamespaceMatcher;
use Rector\PSR4\Contract\PSR4AutoloadNamespaceMatcherInterface;
use Symfony\Component\Console\Application;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;
use Symplify\EasyParallel\ValueObject\EasyParallelConfig; use Symplify\EasyParallel\ValueObject\EasyParallelConfig;
use Symplify\PackageBuilder\Parameter\ParameterProvider;
use Symplify\PackageBuilder\Php\TypeChecker;
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
use Symplify\PackageBuilder\Reflection\PrivatesCaller;
use Symplify\PackageBuilder\Yaml\ParametersMerger; use Symplify\PackageBuilder\Yaml\ParametersMerger;
use Symplify\SmartFileSystem\FileSystemFilter;
use Symplify\SmartFileSystem\FileSystemGuard;
use Symplify\SmartFileSystem\Finder\FinderSanitizer;
use Symplify\SmartFileSystem\Json\JsonFileSystem;
use Symplify\SmartFileSystem\SmartFileSystem;
return static function (RectorConfig $rectorConfig): void { return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/services.php');
$rectorConfig->import(__DIR__ . '/services-rules.php');
// make use of https://github.com/symplify/easy-parallel // make use of https://github.com/symplify/easy-parallel
$rectorConfig->import(EasyParallelConfig::FILE_PATH); $rectorConfig->import(EasyParallelConfig::FILE_PATH);
@ -52,6 +94,19 @@ return static function (RectorConfig $rectorConfig): void {
__DIR__ . '/../packages/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php', __DIR__ . '/../packages/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php',
]); ]);
// psr-4
$services->alias(PSR4AutoloadNamespaceMatcherInterface::class, PSR4NamespaceMatcher::class);
$services->load('Rector\\', __DIR__ . '/../rules')
->exclude([
__DIR__ . '/../rules/*/ValueObject/*',
__DIR__ . '/../rules/*/Rector/*',
__DIR__ . '/../rules/*/Contract/*',
__DIR__ . '/../rules/*/Exception/*',
__DIR__ . '/../rules/*/Enum/*',
__DIR__ . '/../rules/DowngradePhp80/Reflection/SimplePhpParameterReflection.php',
]);
// parallel // parallel
$services->set(ParametersMerger::class); $services->set(ParametersMerger::class);
@ -70,4 +125,101 @@ return static function (RectorConfig $rectorConfig): void {
// require only in dev // require only in dev
$rectorConfig->import(__DIR__ . '/../utils/compiler/config/config.php', null, 'not_found'); $rectorConfig->import(__DIR__ . '/../utils/compiler/config/config.php', null, 'not_found');
$services->load('Rector\Core\\', __DIR__ . '/../src')
->exclude([
__DIR__ . '/../src/Rector',
__DIR__ . '/../src/Console/Style/RectorConsoleOutputStyle.php',
__DIR__ . '/../src/Exception',
__DIR__ . '/../src/DependencyInjection/CompilerPass',
__DIR__ . '/../src/DependencyInjection/Loader',
__DIR__ . '/../src/Kernel',
__DIR__ . '/../src/ValueObject',
__DIR__ . '/../src/Bootstrap',
__DIR__ . '/../src/Enum',
__DIR__ . '/../src/PhpParser/Node/CustomNode',
__DIR__ . '/../src/PhpParser/ValueObject',
__DIR__ . '/../src/functions',
__DIR__ . '/../src/constants.php',
]);
$services->alias(Application::class, ConsoleApplication::class);
$services->set(EmptyConfigurableRectorCollector::class)
->arg('$containerBuilder', service('service_container'));
$services->set(SimpleCallableNodeTraverser::class);
$services->set(BuilderFactory::class);
$services->set(CloningVisitor::class);
$services->set(NodeConnectingVisitor::class);
$services->set(NodeFinder::class);
$services->set(RectorConsoleOutputStyle::class)
->factory([service(RectorConsoleOutputStyleFactory::class), 'create']);
$services->set(Parser::class)
->factory([service(PHPStanServicesFactory::class), 'createPHPStanParser']);
$services->set(Lexer::class)
->factory([service(PHPStanServicesFactory::class), 'createEmulativeLexer']);
// symplify/package-builder
$services->set(FileSystemGuard::class);
$services->set(PrivatesAccessor::class);
$services->set(PrivatesCaller::class);
$services->set(FinderSanitizer::class);
$services->set(FileSystemFilter::class);
$services->set(ParameterProvider::class)
->arg('$container', service('service_container'));
$services->set(SmartFileSystem::class);
$services->set(JsonFileSystem::class);
$services->set(InflectorFactory::class);
$services->set(Inflector::class)
->factory([service(InflectorFactory::class), 'build']);
$services->set(VersionParser::class);
$services->set(TypeChecker::class);
// phpdoc parser
$services->set(\PHPStan\PhpDocParser\Lexer\Lexer::class);
$services->alias(PhpDocParser::class, BetterPhpDocParser::class);
// cache
$services->set(DependencyResolver::class)
->factory([service(PHPStanServicesFactory::class), 'createDependencyResolver']);
$services->set(FileHelper::class)
->factory([service(PHPStanServicesFactory::class), 'createFileHelper']);
$services->set(Cache::class)
->factory([service(CacheFactory::class), 'create']);
// type resolving
$services->set(IntermediateSourceLocator::class);
$services->alias(TypeParser::class, BetterTypeParser::class);
// PHPStan services
$services->set(ReflectionProvider::class)
->factory([service(PHPStanServicesFactory::class), 'createReflectionProvider']);
$services->set(NodeScopeResolver::class)
->factory([service(PHPStanServicesFactory::class), 'createNodeScopeResolver']);
$services->set(ScopeFactory::class)
->factory([service(PHPStanServicesFactory::class), 'createScopeFactory']);
$services->set(TypeNodeResolver::class)
->factory([service(PHPStanServicesFactory::class), 'createTypeNodeResolver']);
$services->set(DynamicSourceLocatorProvider::class)
->factory([service(PHPStanServicesFactory::class), 'createDynamicSourceLocatorProvider']);
$services->set(EditorConfig::class);
$services->set(Printer::class);
$services->alias(PrinterInterface::class, Printer::class);
}; };

View File

@ -1,29 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\PSR4\Composer\PSR4NamespaceMatcher;
use Rector\PSR4\Contract\PSR4AutoloadNamespaceMatcherInterface;
return static function (RectorConfig $rectorConfig): void {
$services = $rectorConfig->services();
$services->defaults()
->public()
->autowire()
->autoconfigure();
// psr-4
$services->alias(PSR4AutoloadNamespaceMatcherInterface::class, PSR4NamespaceMatcher::class);
$services->load('Rector\\', __DIR__ . '/../rules')
->exclude([
__DIR__ . '/../rules/*/ValueObject/*',
__DIR__ . '/../rules/*/Rector/*',
__DIR__ . '/../rules/*/Contract/*',
__DIR__ . '/../rules/*/Exception/*',
__DIR__ . '/../rules/*/Enum/*',
__DIR__ . '/../rules/DowngradePhp80/Reflection/SimplePhpParameterReflection.php',
]);
};

View File

@ -1,163 +0,0 @@
<?php
declare(strict_types=1);
use Composer\Semver\VersionParser;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\Rules\English\InflectorFactory;
use Ergebnis\Json\Printer\Printer;
use Ergebnis\Json\Printer\PrinterInterface;
use Idiosyncratic\EditorConfig\EditorConfig;
use PhpParser\BuilderFactory;
use PhpParser\Lexer;
use PhpParser\NodeFinder;
use PhpParser\NodeVisitor\CloningVisitor;
use PhpParser\NodeVisitor\NodeConnectingVisitor;
use PhpParser\ParserFactory;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\ScopeFactory;
use PHPStan\Dependency\DependencyResolver;
use PHPStan\File\FileHelper;
use PHPStan\Parser\Parser;
use PHPStan\PhpDoc\TypeNodeResolver;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\Reflection\ReflectionProvider;
use Rector\BetterPhpDocParser\PhpDocParser\BetterPhpDocParser;
use Rector\BetterPhpDocParser\PhpDocParser\BetterTypeParser;
use Rector\Caching\Cache;
use Rector\Caching\CacheFactory;
use Rector\Config\RectorConfig;
use Rector\Core\Console\ConsoleApplication;
use Rector\Core\Console\Style\RectorConsoleOutputStyle;
use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory;
use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector;
use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
use Symfony\Component\Console\Application;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
use Symplify\PackageBuilder\Parameter\ParameterProvider;
use Symplify\PackageBuilder\Php\TypeChecker;
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
use Symplify\PackageBuilder\Reflection\PrivatesCaller;
use Symplify\PackageBuilder\Strings\StringFormatConverter;
use Symplify\SmartFileSystem\FileSystemFilter;
use Symplify\SmartFileSystem\FileSystemGuard;
use Symplify\SmartFileSystem\Finder\FinderSanitizer;
use Symplify\SmartFileSystem\Json\JsonFileSystem;
use Symplify\SmartFileSystem\SmartFileSystem;
return static function (RectorConfig $rectorConfig): void {
$services = $rectorConfig->services();
$services->defaults()
->public()
->autowire()
->autoconfigure();
$services->load('Rector\Core\\', __DIR__ . '/../src')
->exclude([
__DIR__ . '/../src/Rector',
__DIR__ . '/../src/Console/Style/RectorConsoleOutputStyle.php',
__DIR__ . '/../src/Exception',
__DIR__ . '/../src/DependencyInjection/CompilerPass',
__DIR__ . '/../src/DependencyInjection/Loader',
__DIR__ . '/../src/Kernel',
__DIR__ . '/../src/ValueObject',
__DIR__ . '/../src/Bootstrap',
__DIR__ . '/../src/Enum',
__DIR__ . '/../src/PhpParser/Node/CustomNode',
__DIR__ . '/../src/PhpParser/ValueObject',
__DIR__ . '/../src/functions',
__DIR__ . '/../src/constants.php',
]);
$services->alias(Application::class, ConsoleApplication::class);
$services->set(FileSystemGuard::class);
$services->set(EmptyConfigurableRectorCollector::class)
->arg('$containerBuilder', service('service_container'));
$services->set(SimpleCallableNodeTraverser::class);
$services->set(ParserFactory::class);
$services->set(BuilderFactory::class);
$services->set(CloningVisitor::class);
$services->set(NodeFinder::class);
$services->set(RectorConsoleOutputStyle::class)
->factory([service(RectorConsoleOutputStyleFactory::class), 'create']);
$services->set(Parser::class)
->factory([service(PHPStanServicesFactory::class), 'createPHPStanParser']);
$services->set(Lexer::class)
->factory([service(PHPStanServicesFactory::class), 'createEmulativeLexer']);
// symplify/package-builder
$services->set(PrivatesAccessor::class);
$services->set(PrivatesCaller::class);
$services->set(FinderSanitizer::class);
$services->set(FileSystemFilter::class);
$services->set(ParameterProvider::class)
->arg('$container', service('service_container'));
$services->set(CommandNaming::class);
$services->set(SmartFileSystem::class);
$services->set(StringFormatConverter::class);
$services->set(JsonFileSystem::class);
$services->set(NodeConnectingVisitor::class);
$services->set(InflectorFactory::class);
$services->set(Inflector::class)
->factory([service(InflectorFactory::class), 'build']);
$services->set(VersionParser::class);
$services->set(TypeChecker::class);
// phpdoc parser
$services->set(\PHPStan\PhpDocParser\Lexer\Lexer::class);
$services->alias(PhpDocParser::class, BetterPhpDocParser::class);
// cache
$services->set(DependencyResolver::class)
->factory([service(PHPStanServicesFactory::class), 'createDependencyResolver']);
$services->set(FileHelper::class)
->factory([service(PHPStanServicesFactory::class), 'createFileHelper']);
$services->set(Cache::class)
->factory([service(CacheFactory::class), 'create']);
// type resolving
$services->set(IntermediateSourceLocator::class);
$services->alias(TypeParser::class, BetterTypeParser::class);
// PHPStan services
$services->set(ReflectionProvider::class)
->factory([service(PHPStanServicesFactory::class), 'createReflectionProvider']);
$services->set(NodeScopeResolver::class)
->factory([service(PHPStanServicesFactory::class), 'createNodeScopeResolver']);
$services->set(ScopeFactory::class)
->factory([service(PHPStanServicesFactory::class), 'createScopeFactory']);
$services->set(TypeNodeResolver::class)
->factory([service(PHPStanServicesFactory::class), 'createTypeNodeResolver']);
$services->set(DynamicSourceLocatorProvider::class)
->factory([service(PHPStanServicesFactory::class), 'createDynamicSourceLocatorProvider']);
$services->set(EditorConfig::class);
$services->set(Printer::class);
$services->alias(PrinterInterface::class, Printer::class);
};

View File

@ -8,13 +8,11 @@ use Iterator;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter; use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\Core\Console\Command\ProcessCommand; use Rector\Core\Console\Command\ProcessCommand;
use Rector\Core\Console\Command\WorkerCommand;
use Rector\Core\Kernel\RectorKernel; use Rector\Core\Kernel\RectorKernel;
use Rector\Parallel\Command\WorkerCommandLineFactory; use Rector\Parallel\Command\WorkerCommandLineFactory;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase; use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
final class WorkerCommandLineFactoryTest extends AbstractKernelTestCase final class WorkerCommandLineFactoryTest extends AbstractKernelTestCase
@ -53,7 +51,7 @@ final class WorkerCommandLineFactoryTest extends AbstractKernelTestCase
$workerCommandLine = $this->workerCommandLineFactory->create( $workerCommandLine = $this->workerCommandLineFactory->create(
self::DUMMY_MAIN_SCRIPT, self::DUMMY_MAIN_SCRIPT,
ProcessCommand::class, ProcessCommand::class,
CommandNaming::classToName(WorkerCommand::class), 'worker',
$arrayInput, $arrayInput,
'identifier', 'identifier',
2000 2000

View File

@ -111,6 +111,7 @@ final class RectorConfig extends ContainerConfigurator
*/ */
public function ruleWithConfiguration(string $rectorClass, array $configuration): void public function ruleWithConfiguration(string $rectorClass, array $configuration): void
{ {
Assert::classExists($rectorClass);
Assert::isAOf($rectorClass, RectorInterface::class); Assert::isAOf($rectorClass, RectorInterface::class);
Assert::isAOf($rectorClass, ConfigurableRectorInterface::class); Assert::isAOf($rectorClass, ConfigurableRectorInterface::class);
@ -134,6 +135,7 @@ final class RectorConfig extends ContainerConfigurator
*/ */
public function rule(string $rectorClass): void public function rule(string $rectorClass): void
{ {
Assert::classExists($rectorClass);
Assert::isAOf($rectorClass, RectorInterface::class); Assert::isAOf($rectorClass, RectorInterface::class);
$services = $this->services(); $services = $this->services();

View File

@ -12,7 +12,6 @@ use React\Socket\ConnectionInterface;
use React\Socket\TcpServer; use React\Socket\TcpServer;
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\Core\Console\Command\ProcessCommand; use Rector\Core\Console\Command\ProcessCommand;
use Rector\Core\Console\Command\WorkerCommand;
use Rector\Core\ValueObject\Error\SystemError; use Rector\Core\ValueObject\Error\SystemError;
use Rector\Core\ValueObject\Reporting\FileDiff; use Rector\Core\ValueObject\Reporting\FileDiff;
use Rector\Parallel\Command\WorkerCommandLineFactory; use Rector\Parallel\Command\WorkerCommandLineFactory;
@ -27,7 +26,6 @@ use Symplify\EasyParallel\Enum\ReactEvent;
use Symplify\EasyParallel\ValueObject\ParallelProcess; use Symplify\EasyParallel\ValueObject\ParallelProcess;
use Symplify\EasyParallel\ValueObject\ProcessPool; use Symplify\EasyParallel\ValueObject\ProcessPool;
use Symplify\EasyParallel\ValueObject\Schedule; use Symplify\EasyParallel\ValueObject\Schedule;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
use Symplify\PackageBuilder\Parameter\ParameterProvider; use Symplify\PackageBuilder\Parameter\ParameterProvider;
use Throwable; use Throwable;
@ -141,7 +139,7 @@ final class ParallelFileProcessor
$workerCommandLine = $this->workerCommandLineFactory->create( $workerCommandLine = $this->workerCommandLineFactory->create(
$mainScript, $mainScript,
ProcessCommand::class, ProcessCommand::class,
CommandNaming::classToName(WorkerCommand::class), 'worker',
$input, $input,
$processIdentifier, $processIdentifier,
$serverPort, $serverPort,

View File

@ -484,6 +484,7 @@ parameters:
- rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php - rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php
- rules/Php70/EregToPcreTransformer.php - rules/Php70/EregToPcreTransformer.php
- rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php - rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php
- src/Kernel/RectorKernel.php
- '#Method Rector\\Core\\Application\\ApplicationFileProcessor\:\:runParallel\(\) should return array\{system_errors\: array<Rector\\Core\\ValueObject\\Error\\SystemError\>, file_diffs\: array<Rector\\Core\\ValueObject\\Reporting\\FileDiff\>\} but returns array#' - '#Method Rector\\Core\\Application\\ApplicationFileProcessor\:\:runParallel\(\) should return array\{system_errors\: array<Rector\\Core\\ValueObject\\Error\\SystemError\>, file_diffs\: array<Rector\\Core\\ValueObject\\Reporting\\FileDiff\>\} but returns array#'
@ -694,4 +695,6 @@ parameters:
- '#Parameter \#2 \$args of class PhpParser\\Node\\Expr\\FuncCall constructor expects array<PhpParser\\Node\\Arg\|PhpParser\\Node\\VariadicPlaceholder>, array<int, PhpParser\\Node\\Arg\|null> given#' - '#Parameter \#2 \$args of class PhpParser\\Node\\Expr\\FuncCall constructor expects array<PhpParser\\Node\\Arg\|PhpParser\\Node\\VariadicPlaceholder>, array<int, PhpParser\\Node\\Arg\|null> given#'
# validate class-string input # validate class-string input
- '#Call to static method Webmozart\\Assert\\Assert\:\:isInstanceOf\(\) with class\-string<Rector\\Caching\\Contract\\ValueObject\\Storage\\CacheStorageInterface> and (.*?) will always evaluate to false#' -
message: '#Call to static method Webmozart\\Assert\\Assert\:\:(.*?)\(\) with (.*?) will always evaluate to (false|true)#'
path: packages/Config/RectorConfig.php

View File

@ -7,8 +7,8 @@ namespace Rector\CodeQuality\Rector\Ternary;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Expr\Ternary;
use Rector\Core\PhpParser\Node\Value\TernaryBracketWrapper;
use Rector\Core\Rector\AbstractRector; use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -17,11 +17,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/ */
final class SwitchNegatedTernaryRector extends AbstractRector final class SwitchNegatedTernaryRector extends AbstractRector
{ {
public function __construct(
private readonly TernaryBracketWrapper $ternaryBracketWrapper
) {
}
public function getRuleDefinition(): RuleDefinition public function getRuleDefinition(): RuleDefinition
{ {
return new RuleDefinition( return new RuleDefinition(
@ -81,7 +76,9 @@ CODE_SAMPLE
[$node->if, $node->else] = [$node->else, $node->if]; [$node->if, $node->else] = [$node->else, $node->if];
if ($node->if instanceof Ternary) { if ($node->if instanceof Ternary) {
$this->ternaryBracketWrapper->wrapWithBracket($node->if); $ternary = $node->if;
$ternary->setAttribute(AttributeKey::KIND, 'wrapped_with_brackets');
$ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null);
} }
return $node; return $node;

View File

@ -4,12 +4,10 @@ declare(strict_types=1);
namespace Rector\Core\Configuration; namespace Rector\Core\Configuration;
use JetBrains\PhpStorm\Immutable;
use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface; use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface;
use Rector\Caching\ValueObject\Storage\FileCacheStorage; use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Symplify\Skipper\ValueObject\Option as SkipperOption; use Symplify\Skipper\ValueObject\Option as SkipperOption;
#[Immutable]
final class Option final class Option
{ {
/** /**

View File

@ -36,6 +36,8 @@ final class InitCommand extends Command
protected function configure(): void protected function configure(): void
{ {
$this->setName('init');
$this->setDescription('Generate rector.php configuration file'); $this->setDescription('Generate rector.php configuration file');
$this->addOption( $this->addOption(

View File

@ -24,7 +24,6 @@ use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
use Symplify\SmartFileSystem\SmartFileInfo; use Symplify\SmartFileSystem\SmartFileInfo;
final class ProcessCommand extends AbstractProcessCommand final class ProcessCommand extends AbstractProcessCommand
@ -47,7 +46,7 @@ final class ProcessCommand extends AbstractProcessCommand
protected function configure(): void protected function configure(): void
{ {
$this->setName(CommandNaming::classToName(self::class)); $this->setName('process');
$this->setDescription('Upgrades or refactors source code with provided rectors'); $this->setDescription('Upgrades or refactors source code with provided rectors');
parent::configure(); parent::configure();

View File

@ -15,7 +15,6 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symplify\EasyParallel\Enum\Action; use Symplify\EasyParallel\Enum\Action;
use Symplify\EasyParallel\Enum\ReactCommand; use Symplify\EasyParallel\Enum\ReactCommand;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
/** /**
* Inspired at: https://github.com/phpstan/phpstan-src/commit/9124c66dcc55a222e21b1717ba5f60771f7dda92 * Inspired at: https://github.com/phpstan/phpstan-src/commit/9124c66dcc55a222e21b1717ba5f60771f7dda92
@ -35,7 +34,7 @@ final class WorkerCommand extends AbstractProcessCommand
protected function configure(): void protected function configure(): void
{ {
$this->setName(CommandNaming::classToName(self::class)); $this->setName('worker');
$this->setDescription('(Internal) Support for parallel process'); $this->setDescription('(Internal) Support for parallel process');
parent::configure(); parent::configure();
} }

View File

@ -28,15 +28,10 @@ final class ConsoleApplication extends Application
/** /**
* @param Command[] $commands * @param Command[] $commands
*/ */
public function __construct(CommandNaming $commandNaming, array $commands = []) public function __construct(array $commands = [])
{ {
parent::__construct(self::NAME, VersionResolver::PACKAGE_VERSION); parent::__construct(self::NAME, VersionResolver::PACKAGE_VERSION);
foreach ($commands as $command) {
$commandName = $commandNaming->resolveFromCommand($command);
$command->setName($commandName);
}
$this->addCommands($commands); $this->addCommands($commands);
$this->setDefaultCommand(CommandNaming::classToName(ProcessCommand::class)); $this->setDefaultCommand(CommandNaming::classToName(ProcessCommand::class));
} }

View File

@ -1,48 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Core\DependencyInjection\CompilerPass;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
final class VerifyRectorServiceExistsCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $containerBuilder): void
{
foreach ($containerBuilder->getDefinitions() as $definition) {
$class = $definition->getClass();
if ($class === null) {
continue;
}
if (! \str_ends_with($class, 'Rector')) {
continue;
}
if (! class_exists($class)) {
throw new ShouldNotHappenException(
sprintf(
'Rector rule "%s" not found, please verify that the class exists and is autoloadable.',
$class
)
);
}
if (! is_a($class, RectorInterface::class, true)) {
throw new ShouldNotHappenException(
sprintf(
'Rector rule "%s" should extend "%s" or implement "%s".',
$class,
AbstractRector::class,
RectorInterface::class
)
);
}
}
}
}

View File

@ -34,7 +34,7 @@ final class RectorContainerFactory
); );
$symfonyStyle->warning($warningMessage); $symfonyStyle->warning($warningMessage);
// to make message noticable // to make message noticable
sleep(3); sleep(5);
} }
/** @var ChangedFilesDetector $changedFilesDetector */ /** @var ChangedFilesDetector $changedFilesDetector */

View File

@ -52,7 +52,6 @@ final class FilesFinder
$filesAndDirectories = $this->filesystemTweaker->resolveWithFnmatch($source); $filesAndDirectories = $this->filesystemTweaker->resolveWithFnmatch($source);
$filePaths = $this->fileSystemFilter->filterFiles($filesAndDirectories); $filePaths = $this->fileSystemFilter->filterFiles($filesAndDirectories);
$directories = $this->fileSystemFilter->filterDirectories($filesAndDirectories); $directories = $this->fileSystemFilter->filterDirectories($filesAndDirectories);
$smartFileInfos = $this->unchangedFilesFilter->filterAndJoinWithDependentFileInfos($filePaths); $smartFileInfos = $this->unchangedFilesFilter->filterAndJoinWithDependentFileInfos($filePaths);

View File

@ -4,39 +4,8 @@ declare(strict_types=1);
namespace Rector\Core\FileSystem; namespace Rector\Core\FileSystem;
use Symplify\SmartFileSystem\FileSystemGuard;
final class FilesystemTweaker final class FilesystemTweaker
{ {
public function __construct(
private readonly FileSystemGuard $fileSystemGuard
) {
}
/**
* This will turn paths like "src/Symfony/Component/*\/Tests" to existing directory paths
*
* @param string[] $directories
* @return string[]
*/
public function resolveDirectoriesWithFnmatch(array $directories): array
{
$absoluteDirectories = [];
foreach ($directories as $directory) {
// is fnmatch for directories
if (\str_contains($directory, '*')) {
$foundDirectories = $this->findDirectoriesInGlob($directory);
$absoluteDirectories = array_merge($absoluteDirectories, $foundDirectories);
} else {
// is classic directory
$this->fileSystemGuard->ensureDirectoryExists($directory, '');
$absoluteDirectories[] = $directory;
}
}
return $absoluteDirectories;
}
/** /**
* This will turn paths like "src/Symfony/Component/*\/Tests" to existing directory paths * This will turn paths like "src/Symfony/Component/*\/Tests" to existing directory paths
* *
@ -59,16 +28,6 @@ final class FilesystemTweaker
return $absolutePathsFound; return $absolutePathsFound;
} }
/**
* @return string[]
*/
private function findDirectoriesInGlob(string $directory): array
{
/** @var string[] $foundDirectories */
$foundDirectories = (array) glob($directory, GLOB_ONLYDIR);
return $foundDirectories;
}
/** /**
* @return string[] * @return string[]
*/ */

View File

@ -10,7 +10,6 @@ use Rector\Core\DependencyInjection\Collector\ConfigureCallValuesCollector;
use Rector\Core\DependencyInjection\CompilerPass\MakeRectorsPublicCompilerPass; use Rector\Core\DependencyInjection\CompilerPass\MakeRectorsPublicCompilerPass;
use Rector\Core\DependencyInjection\CompilerPass\MergeImportedRectorConfigureCallValuesCompilerPass; use Rector\Core\DependencyInjection\CompilerPass\MergeImportedRectorConfigureCallValuesCompilerPass;
use Rector\Core\DependencyInjection\CompilerPass\RemoveSkippedRectorsCompilerPass; use Rector\Core\DependencyInjection\CompilerPass\RemoveSkippedRectorsCompilerPass;
use Rector\Core\DependencyInjection\CompilerPass\VerifyRectorServiceExistsCompilerPass;
use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Exception\ShouldNotHappenException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
@ -87,8 +86,6 @@ final class RectorKernel implements LightKernelInterface
// add all merged arguments of Rector services // add all merged arguments of Rector services
$compilerPasses[] = new MergeImportedRectorConfigureCallValuesCompilerPass($this->configureCallValuesCollector); $compilerPasses[] = new MergeImportedRectorConfigureCallValuesCompilerPass($this->configureCallValuesCollector);
$compilerPasses[] = new VerifyRectorServiceExistsCompilerPass();
$compilerPasses[] = new AutowireArrayParameterCompilerPass(); $compilerPasses[] = new AutowireArrayParameterCompilerPass();
return $compilerPasses; return $compilerPasses;
@ -99,14 +96,12 @@ final class RectorKernel implements LightKernelInterface
*/ */
private function createDefaultConfigFiles(): array private function createDefaultConfigFiles(): array
{ {
$configFiles = []; return [
__DIR__ . '/../../config/config.php',
$configFiles[] = __DIR__ . '/../../config/config.php'; AstralConfig::FILE_PATH,
$configFiles[] = AstralConfig::FILE_PATH; ComposerJsonManipulatorConfig::FILE_PATH,
$configFiles[] = ComposerJsonManipulatorConfig::FILE_PATH; SkipperConfig::FILE_PATH,
$configFiles[] = SkipperConfig::FILE_PATH; ConsoleColorDiffConfig::FILE_PATH,
$configFiles[] = ConsoleColorDiffConfig::FILE_PATH; ];
return $configFiles;
} }
} }

View File

@ -1,17 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Core\PhpParser\Node\Value;
use PhpParser\Node\Expr\Ternary;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class TernaryBracketWrapper
{
public function wrapWithBracket(Ternary $ternary): void
{
$ternary->setAttribute(AttributeKey::KIND, 'wrapped_with_brackets');
$ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
}

View File

@ -53,6 +53,6 @@ final class EmptyConfigurableRectorChecker
} }
// to take time to absorb it // to take time to absorb it
sleep(3); sleep(5);
} }
} }

View File

@ -4,10 +4,8 @@ declare(strict_types=1);
namespace Rector\Core\ValueObject; namespace Rector\Core\ValueObject;
use JetBrains\PhpStorm\Immutable;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter; use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
#[Immutable]
final class Configuration final class Configuration
{ {
/** /**

View File

@ -6,88 +6,77 @@ namespace Rector\Core\ValueObject;
use MyCLabs\Enum\Enum; use MyCLabs\Enum\Enum;
/**
* @api
*/
final class PhpVersion extends Enum final class PhpVersion extends Enum
{ {
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_52 = 50200; public const PHP_52 = 50200;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_53 = 50300; public const PHP_53 = 50300;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_54 = 50400; public const PHP_54 = 50400;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_55 = 50500; public const PHP_55 = 50500;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_56 = 50600; public const PHP_56 = 50600;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_70 = 70000; public const PHP_70 = 70000;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_71 = 70100; public const PHP_71 = 70100;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_72 = 70200; public const PHP_72 = 70200;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_73 = 70300; public const PHP_73 = 70300;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_74 = 70400; public const PHP_74 = 70400;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_80 = 80000; public const PHP_80 = 80000;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_81 = 80100; public const PHP_81 = 80100;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_82 = 80200; public const PHP_82 = 80200;
/** /**
* @api
* @var int * @var int
*/ */
public const PHP_10 = 100000; public const PHP_10 = 100000;

View File

@ -5,15 +5,22 @@ declare(strict_types=1);
namespace Rector\Core\ValueObject; namespace Rector\Core\ValueObject;
use PhpParser\Node; use PhpParser\Node;
use Rector\Core\Contract\Rector\RectorInterface;
final class RectifiedNode final class RectifiedNode
{ {
/**
* @param class-string<RectorInterface> $rectorClass
*/
public function __construct( public function __construct(
private readonly string $rectorClass, private readonly string $rectorClass,
private readonly Node $node private readonly Node $node
) { ) {
} }
/**
* @return class-string<RectorInterface>
*/
public function getRectorClass(): string public function getRectorClass(): string
{ {
return $this->rectorClass; return $this->rectorClass;