From 088186776e8c057554c0ea0b856830bd140e79fc Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 2 May 2025 18:42:03 +0200 Subject: [PATCH 1/6] [config] remove def value --- rector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rector.php b/rector.php index 997d7c85b14..10ffc835ef2 100644 --- a/rector.php +++ b/rector.php @@ -35,7 +35,7 @@ __DIR__ . '/build/build-preload.php', ]) ->withRootFiles() - ->withImportNames(removeUnusedImports: true) + ->withImportNames() ->withSkip([ StringClassNameToClassConstantRector::class, // tests From 8b45a9da04f49ea0b5ef9e80958eb2ce8e54dfd5 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 2 May 2025 18:42:18 +0200 Subject: [PATCH 2/6] typo --- .../Rector/StmtsAwareInterface/DeclareStrictTypesRector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php b/rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php index 7472d7aadcf..9186a0a4f9b 100644 --- a/rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php +++ b/rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php @@ -66,7 +66,7 @@ public function beforeTraverse(array $nodes): ?array return null; } - if ($this->startWithShebang($this->file)) { + if ($this->startsWithShebang($this->file)) { return null; } @@ -126,7 +126,7 @@ public function refactor(Node $node): ?Node return null; } - private function startWithShebang(File $file): bool + private function startsWithShebang(File $file): bool { return str_starts_with($file->getFileContent(), '#!'); } From 5b4cd91f0a950bfae4778470e79ec3cda09694db Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 2 May 2025 18:42:34 +0200 Subject: [PATCH 3/6] skip if no paths found --- src/Application/ApplicationFileProcessor.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Application/ApplicationFileProcessor.php b/src/Application/ApplicationFileProcessor.php index 852a6e32de0..57a0ead6002 100644 --- a/src/Application/ApplicationFileProcessor.php +++ b/src/Application/ApplicationFileProcessor.php @@ -58,14 +58,15 @@ public function __construct( public function run(Configuration $configuration, InputInterface $input): ProcessResult { $filePaths = $this->filesFinder->findFilesInPaths($configuration->getPaths(), $configuration); - $this->missConfigurationReporter->reportVendorInPaths($filePaths); - $this->missConfigurationReporter->reportStartWithShortOpenTag(); // no files found if ($filePaths === []) { return new ProcessResult([], []); } + $this->missConfigurationReporter->reportVendorInPaths($filePaths); + $this->missConfigurationReporter->reportStartWithShortOpenTag(); + $this->configureCustomErrorHandler(); /** From c708a22f6cc6cd96d788b857e088d06821a1e73a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 2 May 2025 18:44:11 +0200 Subject: [PATCH 4/6] [parallel] bump default threads from 16 to 32 to keep up with modern technology, alligned with phpstan setup --- src/Config/RectorConfig.php | 8 ++++++-- src/Configuration/RectorConfigBuilder.php | 3 ++- src/Enum/Config/Defaults.php | 13 +++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/Enum/Config/Defaults.php diff --git a/src/Config/RectorConfig.php b/src/Config/RectorConfig.php index f5c7c12ba53..d206964ab09 100644 --- a/src/Config/RectorConfig.php +++ b/src/Config/RectorConfig.php @@ -14,6 +14,7 @@ use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\Contract\Rector\RectorInterface; use Rector\DependencyInjection\Laravel\ContainerMemento; +use Rector\Enum\Config\Defaults; use Rector\Exception\ShouldNotHappenException; use Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver; use Rector\Validation\RectorConfigValidator; @@ -93,8 +94,11 @@ public function disableParallel(): void SimpleParameterProvider::setParameter(Option::PARALLEL, false); } - public function parallel(int $processTimeout = 120, int $maxNumberOfProcess = 16, int $jobSize = 16): void - { + public function parallel( + int $processTimeout = 120, + int $maxNumberOfProcess = Defaults::PARALLEL_MAX_NUMBER_OF_PROCESS, + int $jobSize = 16 + ): void { SimpleParameterProvider::setParameter(Option::PARALLEL, true); SimpleParameterProvider::setParameter(Option::PARALLEL_JOB_TIMEOUT_IN_SECONDS, $processTimeout); SimpleParameterProvider::setParameter(Option::PARALLEL_MAX_NUMBER_OF_PROCESSES, $maxNumberOfProcess); diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index 03479885993..00e26121d23 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -20,6 +20,7 @@ use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\Contract\Rector\RectorInterface; use Rector\Doctrine\Set\DoctrineSetList; +use Rector\Enum\Config\Defaults; use Rector\Exception\Configuration\InvalidConfigurationException; use Rector\Php\PhpVersionResolver\ComposerJsonPhpVersionResolver; use Rector\PHPUnit\Set\PHPUnitSetList; @@ -90,7 +91,7 @@ final class RectorConfigBuilder private int $parallelTimeoutSeconds = 120; - private int $parallelMaxNumberOfProcess = 16; + private int $parallelMaxNumberOfProcess = Defaults::PARALLEL_MAX_NUMBER_OF_PROCESS; private int $parallelJobSize = 16; diff --git a/src/Enum/Config/Defaults.php b/src/Enum/Config/Defaults.php new file mode 100644 index 00000000000..f2f26009edc --- /dev/null +++ b/src/Enum/Config/Defaults.php @@ -0,0 +1,13 @@ + Date: Fri, 2 May 2025 18:44:14 +0200 Subject: [PATCH 5/6] typo --- .../SourceLocatorProvider/DynamicSourceLocatorProvider.php | 2 +- src/StaticReflection/DynamicSourceLocatorDecorator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php b/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php index 15912b63bc2..ac4236a44cb 100644 --- a/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php +++ b/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php @@ -78,7 +78,7 @@ public function provide(): SourceLocator return $this->aggregateSourceLocator = new AggregateSourceLocator($sourceLocators); } - public function isPathsEmpty(): bool + public function arePathsEmpty(): bool { return $this->filePaths === [] && $this->directories === []; } diff --git a/src/StaticReflection/DynamicSourceLocatorDecorator.php b/src/StaticReflection/DynamicSourceLocatorDecorator.php index 7263db4371d..1003fb20dcc 100644 --- a/src/StaticReflection/DynamicSourceLocatorDecorator.php +++ b/src/StaticReflection/DynamicSourceLocatorDecorator.php @@ -41,6 +41,6 @@ public function addPaths(array $paths): void public function isPathsEmpty(): bool { - return $this->dynamicSourceLocatorProvider->isPathsEmpty(); + return $this->dynamicSourceLocatorProvider->arePathsEmpty(); } } From b789f2d053c44d15f7839832fc5a74219ec3a0c7 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 2 May 2025 18:44:50 +0200 Subject: [PATCH 6/6] [solid] make AbstractRector::leave() final, to avoid breaking removing mechanism in child classes --- src/Console/Command/ProcessCommand.php | 2 +- src/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php | 2 +- src/Rector/AbstractRector.php | 2 +- src/StaticReflection/DynamicSourceLocatorDecorator.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index f5a08310ffb..91ae69da128 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int // 2. add files and directories to static locator $this->dynamicSourceLocatorDecorator->addPaths($paths); - if ($this->dynamicSourceLocatorDecorator->isPathsEmpty()) { + if ($this->dynamicSourceLocatorDecorator->arePathsEmpty()) { // read from rector.php, no paths definition needs withPaths() config if ($paths === []) { $this->symfonyStyle->error( diff --git a/src/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php b/src/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php index 1dcdf9c5553..20301ccab3d 100644 --- a/src/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php +++ b/src/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php @@ -82,7 +82,7 @@ private function resolveToStringNativeTypeFromAstResolver(PhpMethodReflection $p if ($class instanceof ClassLike) { $classMethod = $class->getMethod($phpMethodReflection->getName()); - if ($classMethod instanceof ClassMethod && !$classMethod->returnType instanceof Node) { + if ($classMethod instanceof ClassMethod && ! $classMethod->returnType instanceof Node) { return new MixedType(); } } diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index c893c3a467b..85b9d1a0442 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -190,7 +190,7 @@ final public function enterNode(Node $node): int|Node|null * Replacing nodes in leaveNode() method avoids infinite recursion * see"infinite recursion" in https://github.com/nikic/PHP-Parser/blob/master/doc/component/Walking_the_AST.markdown */ - public function leaveNode(Node $node): array|int|Node|null + final public function leaveNode(Node $node): array|int|Node|null { if ($node->hasAttribute(AttributeKey::ORIGINAL_NODE)) { return null; diff --git a/src/StaticReflection/DynamicSourceLocatorDecorator.php b/src/StaticReflection/DynamicSourceLocatorDecorator.php index 1003fb20dcc..c74c6d685ff 100644 --- a/src/StaticReflection/DynamicSourceLocatorDecorator.php +++ b/src/StaticReflection/DynamicSourceLocatorDecorator.php @@ -39,7 +39,7 @@ public function addPaths(array $paths): void $this->dynamicSourceLocatorProvider->addDirectories($directories); } - public function isPathsEmpty(): bool + public function arePathsEmpty(): bool { return $this->dynamicSourceLocatorProvider->arePathsEmpty(); }