From 29838d0c0df88974453465ed21042b32166abfb1 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 28 Dec 2021 14:53:11 +0100 Subject: [PATCH] [Parallel] Process smaller chunk of files at once (#1587) Co-authored-by: GitHub Action --- .github/workflows/rector.yaml | 2 +- bin/generate-changelog.php | 11 ++++++++--- config/parameters.php | 4 ++-- config/set/php70.php | 2 -- .../ReplaceArgumentDefaultValueRector.php | 15 ++++++++++++--- ...ctionArgumentDefaultValueReplacerRector.php | 14 +++++++++++--- .../FuncCall/SimplifyRegexPatternRector.php | 18 ++++++++++++++++-- .../FuncCall/MysqlFuncCallToMysqliRector.php | 8 +++++++- .../FuncCall/RemoveReferenceFromCallRector.php | 17 +++++++++++++---- .../Rector/FuncCall/RandomFunctionRector.php | 4 ++-- .../Rector/FuncCall/RegexDashEscapeRector.php | 9 ++++++++- .../Rector/Property/TypedPropertyRector.php | 4 ++++ .../Regex/RegexPatternArgumentManipulator.php | 12 ++++-------- src/PhpParser/AstResolver.php | 4 ++-- 14 files changed, 90 insertions(+), 34 deletions(-) diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml index a768150207d..290cf06997b 100644 --- a/.github/workflows/rector.yaml +++ b/.github/workflows/rector.yaml @@ -33,7 +33,7 @@ jobs: - config utils scoper.php runs-on: ubuntu-latest - timeout-minutes: 30 + timeout-minutes: 10 steps: # workaround for missing secret in fork PRs - see https://github.com/actions/checkout/issues/298 diff --git a/bin/generate-changelog.php b/bin/generate-changelog.php index ead0b11c447..9f1cf0056f1 100755 --- a/bin/generate-changelog.php +++ b/bin/generate-changelog.php @@ -54,6 +54,11 @@ final class GenerateChangelogCommand extends Command */ private const HASH = 'hash'; + /** + * @var string + */ + private const MESSAGE = 'message'; + protected function configure(): void { $this->setName(CommandNaming::classToName(self::class)); @@ -131,9 +136,9 @@ final class GenerateChangelogCommand extends Command } // clean commit from duplicating issue number - $commitMatch = Strings::match($commit['message'], '#(.*?)( \(\#\d+\))?$#ms'); + $commitMatch = Strings::match($commit[self::MESSAGE], '#(.*?)( \(\#\d+\))?$#ms'); - $commit = $commitMatch[1] ?? $commit['message']; + $commit = $commitMatch[1] ?? $commit[self::MESSAGE]; $changelogLine = sprintf( '* %s (%s)%s%s', @@ -156,7 +161,7 @@ final class GenerateChangelogCommand extends Command return self::SUCCESS; } - protected function createThanks(string|null $thanks): string + private function createThanks(string|null $thanks): string { if ($thanks === null) { return ''; diff --git a/config/parameters.php b/config/parameters.php index 1f25b932e0f..c0e9e8a31c8 100644 --- a/config/parameters.php +++ b/config/parameters.php @@ -19,8 +19,8 @@ return static function (ContainerConfigurator $containerConfigurator): void { // parallel $parameters->set(Option::PARALLEL, false); - $parameters->set(Option::PARALLEL_MAX_NUMBER_OF_PROCESSES, 20); - $parameters->set(Option::PARALLEL_JOB_SIZE, 60); + $parameters->set(Option::PARALLEL_MAX_NUMBER_OF_PROCESSES, 16); + $parameters->set(Option::PARALLEL_JOB_SIZE, 20); // FQN class importing $parameters->set(Option::AUTO_IMPORT_NAMES, false); diff --git a/config/set/php70.php b/config/set/php70.php index 8657511ced3..0908ecb074b 100644 --- a/config/set/php70.php +++ b/config/set/php70.php @@ -24,8 +24,6 @@ use Rector\Php70\Rector\Variable\WrapVariableVariableNameInCurlyBracesRector; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - $containerConfigurator->import(__DIR__ . '/mysql-to-mysqli.php'); - $services = $containerConfigurator->services(); $services->set(Php4ConstructorRector::class); diff --git a/rules/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php b/rules/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php index 1b9fcf3c715..ae3876a04e6 100644 --- a/rules/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php +++ b/rules/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php @@ -78,8 +78,10 @@ CODE_SAMPLE /** * @param MethodCall|StaticCall|ClassMethod $node */ - public function refactor(Node $node): MethodCall | StaticCall | ClassMethod + public function refactor(Node $node): MethodCall | StaticCall | ClassMethod | null { + $hasChanged = false; + foreach ($this->replacedArguments as $replacedArgument) { if (! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType( $node, @@ -92,10 +94,17 @@ CODE_SAMPLE continue; } - $this->argumentDefaultValueReplacer->processReplaces($node, $replacedArgument); + $replacedNode = $this->argumentDefaultValueReplacer->processReplaces($node, $replacedArgument); + if ($replacedNode instanceof Node) { + $hasChanged = true; + } } - return $node; + if ($hasChanged) { + return $node; + } + + return null; } /** diff --git a/rules/Arguments/Rector/FuncCall/FunctionArgumentDefaultValueReplacerRector.php b/rules/Arguments/Rector/FuncCall/FunctionArgumentDefaultValueReplacerRector.php index 915349e19b6..ceb2610b63c 100644 --- a/rules/Arguments/Rector/FuncCall/FunctionArgumentDefaultValueReplacerRector.php +++ b/rules/Arguments/Rector/FuncCall/FunctionArgumentDefaultValueReplacerRector.php @@ -67,17 +67,25 @@ CODE_SAMPLE /** * @param FuncCall $node */ - public function refactor(Node $node): FuncCall + public function refactor(Node $node): FuncCall|null { + $hasChanged = false; foreach ($this->replacedArguments as $replacedArgument) { if (! $this->isName($node->name, $replacedArgument->getFunction())) { continue; } - $this->argumentDefaultValueReplacer->processReplaces($node, $replacedArgument); + $changedNode = $this->argumentDefaultValueReplacer->processReplaces($node, $replacedArgument); + if ($changedNode instanceof Node) { + $hasChanged = true; + } } - return $node; + if ($hasChanged) { + return $node; + } + + return null; } /** diff --git a/rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php b/rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php index c9f16f567b1..dd31abf5158 100644 --- a/rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php +++ b/rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php @@ -82,16 +82,30 @@ CODE_SAMPLE return null; } + $hasChanged = false; + foreach ($patterns as $pattern) { foreach (self::COMPLEX_PATTERN_TO_SIMPLE as $complexPattern => $simple) { - $pattern->value = Strings::replace( + $originalValue = $pattern->value; + $simplifiedValue = Strings::replace( $pattern->value, '#' . preg_quote($complexPattern, '#') . '#', $simple ); + + if ($originalValue === $simplifiedValue) { + continue; + } + + $pattern->value = $simplifiedValue; + $hasChanged = true; } } - return $node; + if ($hasChanged) { + return $node; + } + + return null; } } diff --git a/rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php b/rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php index 7b7c791a505..f64e1415ede 100644 --- a/rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php +++ b/rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php @@ -69,6 +69,8 @@ CODE_SAMPLE if ($this->isName($node, 'mysql_list_dbs')) { $node->name = new Name(self::MYSQLI_QUERY); $node->args[0] = new Arg(new String_('SHOW DATABASES')); + + return $node; } if ($this->isName( @@ -79,14 +81,18 @@ CODE_SAMPLE $node->args[0]->value = $this->joinStringWithNode('SHOW COLUMNS FROM', $node->args[1]->value); unset($node->args[1]); + + return $node; } if ($this->isName($node, 'mysql_list_tables') && $node->args[0] instanceof Arg) { $node->name = new Name(self::MYSQLI_QUERY); $node->args[0]->value = $this->joinStringWithNode('SHOW TABLES FROM', $node->args[0]->value); + + return $node; } - return $node; + return null; } private function processMysqlCreateDb(FuncCall $funcCall): ?FuncCall diff --git a/rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php b/rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php index ba9e4941606..83492e731e6 100644 --- a/rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php +++ b/rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php @@ -61,18 +61,27 @@ CODE_SAMPLE /** * @param FuncCall $node */ - public function refactor(Node $node): FuncCall + public function refactor(Node $node): FuncCall|null { + $hasChanged = false; + foreach ($node->args as $nodeArg) { if (! $nodeArg instanceof Arg) { continue; } - if ($nodeArg->byRef) { - $nodeArg->byRef = false; + if (! $nodeArg->byRef) { + continue; } + + $nodeArg->byRef = false; + $hasChanged = true; } - return $node; + if ($hasChanged) { + return $node; + } + + return null; } } diff --git a/rules/Php70/Rector/FuncCall/RandomFunctionRector.php b/rules/Php70/Rector/FuncCall/RandomFunctionRector.php index 0fb1894dae8..8820622969d 100644 --- a/rules/Php70/Rector/FuncCall/RandomFunctionRector.php +++ b/rules/Php70/Rector/FuncCall/RandomFunctionRector.php @@ -49,7 +49,7 @@ final class RandomFunctionRector extends AbstractRector implements MinPhpVersion /** * @param FuncCall $node */ - public function refactor(Node $node): FuncCall + public function refactor(Node $node): FuncCall|null { foreach (self::OLD_TO_NEW_FUNCTION_NAMES as $oldFunctionName => $newFunctionName) { if ($this->isName($node, $oldFunctionName)) { @@ -65,7 +65,7 @@ final class RandomFunctionRector extends AbstractRector implements MinPhpVersion } } - return $node; + return null; } public function provideMinPhpVersion(): int diff --git a/rules/Php73/Rector/FuncCall/RegexDashEscapeRector.php b/rules/Php73/Rector/FuncCall/RegexDashEscapeRector.php index e5e394e1dca..fa87d44689a 100644 --- a/rules/Php73/Rector/FuncCall/RegexDashEscapeRector.php +++ b/rules/Php73/Rector/FuncCall/RegexDashEscapeRector.php @@ -87,15 +87,22 @@ CODE_SAMPLE return null; } + $hasChanged = false; + foreach ($regexArguments as $regexArgument) { if (StringUtils::isMatch($regexArgument->value, self::THREE_BACKSLASH_FOR_ESCAPE_NEXT_REGEX)) { continue; } $this->escapeStringNode($regexArgument); + $hasChanged = true; } - return $node; + if ($hasChanged) { + return $node; + } + + return null; } private function escapeStringNode(String_ $string): void diff --git a/rules/Php74/Rector/Property/TypedPropertyRector.php b/rules/Php74/Rector/Property/TypedPropertyRector.php index a3cd6e5bbaa..2383cdb23ab 100644 --- a/rules/Php74/Rector/Property/TypedPropertyRector.php +++ b/rules/Php74/Rector/Property/TypedPropertyRector.php @@ -99,6 +99,10 @@ CODE_SAMPLE public function refactor(Node $node): ?Node { $scope = $node->getAttribute(AttributeKey::SCOPE); + if (! $scope instanceof Scope) { + return null; + } + if ($this->shouldSkipProperty($node, $scope)) { return null; } diff --git a/src/Php/Regex/RegexPatternArgumentManipulator.php b/src/Php/Regex/RegexPatternArgumentManipulator.php index 348f4219e86..9f7c381b660 100644 --- a/src/Php/Regex/RegexPatternArgumentManipulator.php +++ b/src/Php/Regex/RegexPatternArgumentManipulator.php @@ -62,17 +62,13 @@ final class RegexPatternArgumentManipulator /** * @return String_[] */ - public function matchCallArgumentWithRegexPattern(Expr $expr): array + public function matchCallArgumentWithRegexPattern(FuncCall|StaticCall $call): array { - if ($expr instanceof FuncCall) { - return $this->processFuncCall($expr); + if ($call instanceof FuncCall) { + return $this->processFuncCall($call); } - if ($expr instanceof StaticCall) { - return $this->processStaticCall($expr); - } - - return []; + return $this->processStaticCall($call); } /** diff --git a/src/PhpParser/AstResolver.php b/src/PhpParser/AstResolver.php index d6b76e10738..0cde2cbb053 100644 --- a/src/PhpParser/AstResolver.php +++ b/src/PhpParser/AstResolver.php @@ -356,7 +356,7 @@ final class AstResolver return null; } - $reflectionFunction = $this->reflectionProvider->getFunction($funcCall->name, $scope); - return $this->resolveFunctionFromFunctionReflection($reflectionFunction); + $functionReflection = $this->reflectionProvider->getFunction($funcCall->name, $scope); + return $this->resolveFunctionFromFunctionReflection($functionReflection); } }