Skip to content

Commit

Permalink
feat: add parallel config
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed May 29, 2024
1 parent 6aa22f6 commit 5fc57b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
->inDir(__DIR__ . '/src')
->inDir(__DIR__ . '/tests')
->addFiles([__FILE__])
->useParallelConfig()
->getConfig()
;

Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---

version: '3.9'

services:
app:
image: wayofdev/php-dev:8.3-cli-alpine-latest
Expand Down
20 changes: 20 additions & 0 deletions src/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use PhpCsFixer\Config;
use PhpCsFixer\ConfigInterface;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfig;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

use function call_user_func_array;
use function get_class;
Expand Down Expand Up @@ -86,6 +88,24 @@ public function getConfig(): ConfigInterface
return $this->config->setRules($this->ruleSet->rules());
}

/**
* Wrapper method to set parallel config.
*
* @param positive-int|null $maxProcesses
* @param positive-int|null $filesPerProcess
* @param positive-int|null $processTimeout
*/
public function useParallelConfig(?int $maxProcesses = null, ?int $filesPerProcess = null, ?int $processTimeout = null): self
{
if ($maxProcesses !== null && $filesPerProcess !== null && $processTimeout !== null) {
$this->config->setParallelConfig(new ParallelConfig($maxProcesses, $filesPerProcess, $processTimeout));
} else {
$this->config->setParallelConfig(ParallelConfigFactory::detect());
}

return $this;
}

private function getFinder(): Finder
{
return $this->config->getFinder();
Expand Down

0 comments on commit 5fc57b5

Please sign in to comment.