From 5fc57b54bdddd7fd1987e3427190fb3ab1ce655f Mon Sep 17 00:00:00 2001 From: lotyp Date: Wed, 29 May 2024 11:39:29 +0300 Subject: [PATCH] feat: add parallel config --- .php-cs-fixer.dist.php | 1 + docker-compose.yaml | 2 -- src/ConfigBuilder.php | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 4c015eb..179d559 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -11,6 +11,7 @@ ->inDir(__DIR__ . '/src') ->inDir(__DIR__ . '/tests') ->addFiles([__FILE__]) + ->useParallelConfig() ->getConfig() ; diff --git a/docker-compose.yaml b/docker-compose.yaml index 623965f..b46cfec 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,5 @@ --- -version: '3.9' - services: app: image: wayofdev/php-dev:8.3-cli-alpine-latest diff --git a/src/ConfigBuilder.php b/src/ConfigBuilder.php index 54ab11e..af398df 100644 --- a/src/ConfigBuilder.php +++ b/src/ConfigBuilder.php @@ -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; @@ -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();