Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds 'parallel' option support to phpcs task. #1155

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/tasks/phpcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ grumphp:
triggered_by: [php]
exclude: []
show_sniffs_error_path: true
parallel: null
```

**standard**
Expand Down Expand Up @@ -136,6 +137,12 @@ A list of rules that should not be checked. Leave this option blank to run all c

Displays the sniff that triggered the error, allowing you to more easily find the specific rules with their namespaces.

**parallel**

*Default: null*

Determines the number of processes that phpcs / phpcbf will use when running. Defaults to a single process.

## Framework presets

### Symfony 2
Expand Down
5 changes: 4 additions & 1 deletion src/Task/Phpcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
'report' => 'full',
'report_width' => null,
'exclude' => [],
'show_sniffs_error_path' => true
'show_sniffs_error_path' => true,
'parallel' => null,
]);

$resolver->addAllowedTypes('standard', ['array', 'null', 'string']);
Expand All @@ -64,6 +65,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
$resolver->addAllowedTypes('report_width', ['null', 'int']);
$resolver->addAllowedTypes('exclude', ['array']);
$resolver->addAllowedTypes('show_sniffs_error_path', ['bool']);
$resolver->addAllowedTypes('parallel', ['null', 'int']);

return ConfigOptionsResolver::fromOptionsResolver($resolver);
}
Expand Down Expand Up @@ -161,6 +163,7 @@ private function addArgumentsFromConfig(
$arguments->addOptionalCommaSeparatedArgument('--ignore=%s', $config['ignore_patterns']);
$arguments->addOptionalCommaSeparatedArgument('--exclude=%s', $config['exclude']);
$arguments->addOptionalArgument('-s', $config['show_sniffs_error_path']);
$arguments->addOptionalArgument('--parallel=%s', $config['parallel']);

return $arguments;
}
Expand Down
18 changes: 17 additions & 1 deletion test/Unit/Task/PhpcsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function provideConfigurableOptions(): iterable
'report' => 'full',
'report_width' => null,
'exclude' => [],
'show_sniffs_error_path' => true
'show_sniffs_error_path' => true,
'parallel' => null,
]
];
}
Expand Down Expand Up @@ -357,6 +358,21 @@ public function provideExternalTaskRuns(): iterable
$this->expectFileList('hello.php'.PHP_EOL.'hello2.php'),
]
];
yield 'parallel' => [
[
'parallel' => 4,
],
$this->mockContext(RunContext::class, ['hello.php', 'hello2.php']),
'phpcs',
[
'--extensions=php',
'--report=full',
'-s',
'--parallel=4',
'--report-json',
$this->expectFileList('hello.php'.PHP_EOL.'hello2.php'),
]
];
}

private function expectFileList(string $expectedContents): callable
Expand Down