From c336cedb2c3cc2e485f0368e7a8c711bdc552359 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Thu, 23 Oct 2025 14:05:28 +0200 Subject: [PATCH 1/4] Added syntax sugar to configure parallel run for PHP CS Fixer * Added `\Ibexa\CodeStyle\PhpCsFixer\InternalConfigFactory::runInParallel` --- src/lib/PhpCsFixer/InternalConfigFactory.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/PhpCsFixer/InternalConfigFactory.php b/src/lib/PhpCsFixer/InternalConfigFactory.php index 2035fd9..b2919b4 100644 --- a/src/lib/PhpCsFixer/InternalConfigFactory.php +++ b/src/lib/PhpCsFixer/InternalConfigFactory.php @@ -11,6 +11,8 @@ use Composer\InstalledVersions; use Ibexa\CodeStyle\PhpCsFixer\Sets\RuleSetInterface; use PhpCsFixer\ConfigInterface; +use PhpCsFixer\ParallelAwareConfigInterface; +use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; /** * Factory for Config instance that should be used for all internal Ibexa packages. @@ -24,6 +26,8 @@ final class InternalConfigFactory private RuleSetInterface $ruleSet; + private bool $runInParallel = false; + /** * @param array $rules */ @@ -46,6 +50,13 @@ public function getRuleSet(): RuleSetInterface return $this->ruleSet ??= $this->createRuleSetFromPackage(InstalledVersions::getRootPackage()); } + public function runInParallel(bool $runInParallel = true): self + { + $this->runInParallel = $runInParallel; + + return $this; + } + /** * @param array{name: string, version: string, pretty_version?: string} $package */ @@ -78,11 +89,15 @@ public function buildConfig(): ConfigInterface $this->customRules, )); + if ($this->runInParallel && $config instanceof ParallelAwareConfigInterface) { + $config->setParallelConfig(ParallelConfigFactory::detect()); + } + return $config; } - public static function build(): ConfigInterface + public static function build(bool $runInParallel = false): ConfigInterface { - return (new self())->buildConfig(); + return (new self())->runInParallel($runInParallel)->buildConfig(); } } From d2631c4f3a04bf17d9c3472cb0c0e8e7c42cce4b Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Thu, 23 Oct 2025 14:05:54 +0200 Subject: [PATCH 2/4] [Tests] Added coverage for configuring parallel run --- .../PhpCsFixer/InternalConfigFactoryTest.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/lib/PhpCsFixer/InternalConfigFactoryTest.php b/tests/lib/PhpCsFixer/InternalConfigFactoryTest.php index e85f80c..9e360fb 100644 --- a/tests/lib/PhpCsFixer/InternalConfigFactoryTest.php +++ b/tests/lib/PhpCsFixer/InternalConfigFactoryTest.php @@ -11,6 +11,7 @@ use Ibexa\CodeStyle\PhpCsFixer\InternalConfigFactory; use Ibexa\CodeStyle\PhpCsFixer\Sets\Ibexa46RuleSet; use Ibexa\CodeStyle\PhpCsFixer\Sets\Ibexa50RuleSet; +use PhpCsFixer\ParallelAwareConfigInterface; use PHPUnit\Framework\TestCase; use ReflectionClass; use ReflectionMethod; @@ -40,6 +41,8 @@ protected function setUp(): void * * @param array{name: string, version: string, pretty_version?: string} $package * @param class-string $expectedRuleSetClass + * + * @throws \ReflectionException */ public function testVersionBasedRuleSetSelection( array $package, @@ -98,4 +101,39 @@ public function testWithRuleSet(): void self::assertSame($customRuleSet, $this->factory->getRuleSet()); } + + public function testRunInParallel(): void + { + // Note: sequential test instead of separate test cases on purpose + + // sanity check + /** @var ParallelAwareConfigInterface $config */ + $config = $this->factory->buildConfig(); + self::assertSame(1, $config->getParallelConfig()->getMaxProcesses()); + + $this->factory->runInParallel(); + /** @var ParallelAwareConfigInterface $config */ + $config = $this->factory->buildConfig(); + self::assertGreaterThan(1, $config->getParallelConfig()->getMaxProcesses()); + + // reset test + $this->factory->runInParallel(false); + /** @var ParallelAwareConfigInterface $config */ + $config = $this->factory->buildConfig(); + self::assertSame(1, $config->getParallelConfig()->getMaxProcesses()); + } + + public function testBuildWithoutRunInParallel(): void + { + $config = InternalConfigFactory::build(); + self::assertInstanceOf(ParallelAwareConfigInterface::class, $config); + self::assertSame(1, $config->getParallelConfig()->getMaxProcesses()); + } + + public function testBuildWithRunInParallel(): void + { + $config = InternalConfigFactory::build(true); + self::assertInstanceOf(ParallelAwareConfigInterface::class, $config); + self::assertGreaterThan(1, $config->getParallelConfig()->getMaxProcesses()); + } } From 0024ff83d409b2dbfef50df6d6d00fb44138409e Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Thu, 23 Oct 2025 14:06:38 +0200 Subject: [PATCH 3/4] [Doc] Documented parallel run configuration --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 05f5eb0..28cd73a 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,16 @@ $config->setFinder( return $config; ``` +> [!TIP] +> You can configure a parallel run of PHP CS Fixer by either calling: +> ```php +> $factory->runInParallel(); +> ``` +> or +> ```php +> InternalConfigFactory::build(runInParallel: true) +> ``` + ### Ibexa packages Create a `.php-cs-fixer.php` file in your project root directory with the following content: From d53be97c20fb84e89f8cb3965db75ec868f24e08 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Wed, 29 Oct 2025 11:36:50 +0100 Subject: [PATCH 4/4] [CS] Enabled parallel run in the local Ibexa Code Style config --- .php-cs-fixer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 2a0dee5..c96c6cc 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -14,7 +14,7 @@ ->files()->name('*.php'); $configFactory = new InternalConfigFactory(); -$configFactory->withRuleSet(new Sets\Ibexa50RuleSet()); +$configFactory->runInParallel()->withRuleSet(new Sets\Ibexa50RuleSet()); $config = $configFactory->buildConfig(); $config->setFinder($finder);