Skip to content

Commit

Permalink
[Parallel] Process smaller chunk of files at once (#1587)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
TomasVotruba and actions-user committed Dec 28, 2021
1 parent fa72490 commit 29838d0
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions bin/generate-changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -131,9 +136,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

// 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',
Expand All @@ -156,7 +161,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::SUCCESS;
}

protected function createThanks(string|null $thanks): string
private function createThanks(string|null $thanks): string
{
if ($thanks === null) {
return '';
Expand Down
4 changes: 2 additions & 2 deletions config/parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

// 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);
Expand Down
2 changes: 0 additions & 2 deletions config/set/php70.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ public function getNodeTypes(): array
/**
* @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,
Expand All @@ -92,10 +94,17 @@ public function refactor(Node $node): MethodCall | StaticCall | ClassMethod
continue;
}

$this->argumentDefaultValueReplacer->processReplaces($node, $replacedArgument);
$replacedNode = $this->argumentDefaultValueReplacer->processReplaces($node, $replacedArgument);
if ($replacedNode instanceof Node) {
$hasChanged = true;
}
}

if ($hasChanged) {
return $node;
}

return $node;
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,25 @@ public function getNodeTypes(): array
/**
* @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;
}
}

if ($hasChanged) {
return $node;
}

return $node;
return null;
}

/**
Expand Down
18 changes: 16 additions & 2 deletions rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,30 @@ public function refactor(Node $node): ?Node
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function refactor(Node $node): ?FuncCall
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(
Expand All @@ -79,14 +81,18 @@ public function refactor(Node $node): ?FuncCall
$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
Expand Down
17 changes: 13 additions & 4 deletions rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,27 @@ public function getNodeTypes(): array
/**
* @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;
}

if ($hasChanged) {
return $node;
}

return $node;
return null;
}
}
4 changes: 2 additions & 2 deletions rules/Php70/Rector/FuncCall/RandomFunctionRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getNodeTypes(): array
/**
* @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)) {
Expand All @@ -65,7 +65,7 @@ public function refactor(Node $node): FuncCall
}
}

return $node;
return null;
}

public function provideMinPhpVersion(): int
Expand Down
9 changes: 8 additions & 1 deletion rules/Php73/Rector/FuncCall/RegexDashEscapeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,22 @@ public function refactor(Node $node): ?Node
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;
}

if ($hasChanged) {
return $node;
}

return $node;
return null;
}

private function escapeStringNode(String_ $string): void
Expand Down
4 changes: 4 additions & 0 deletions rules/Php74/Rector/Property/TypedPropertyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
$scope = $node->getAttribute(AttributeKey::SCOPE);
if (! $scope instanceof Scope) {
return null;
}

if ($this->shouldSkipProperty($node, $scope)) {
return null;
}
Expand Down
12 changes: 4 additions & 8 deletions src/Php/Regex/RegexPatternArgumentManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,13 @@ public function __construct(
/**
* @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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/PhpParser/AstResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private function resolveFunctionFromFuncCall(FuncCall $funcCall, Scope $scope):
return null;
}

$reflectionFunction = $this->reflectionProvider->getFunction($funcCall->name, $scope);
return $this->resolveFunctionFromFunctionReflection($reflectionFunction);
$functionReflection = $this->reflectionProvider->getFunction($funcCall->name, $scope);
return $this->resolveFunctionFromFunctionReflection($functionReflection);
}
}

0 comments on commit 29838d0

Please sign in to comment.