Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 00c2960

Browse files
authored
UX: enable parallel runner by default (#9408)
1 parent 3e9f3e0 commit 00c2960

12 files changed

Lines changed: 19 additions & 48 deletions

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PHP_CS_FIXER_IGNORE_MISMATCHED_RULES_EXCEPTIONS= # `0` / `1`, default is `0` - d
66
## @deprecated
77
## @TODO remove in 4.0
88
PHP_CS_FIXER_IGNORE_ENV= # `0` / `1`, default is `0` - ignore environment variables; use Config::setUnsupportedPhpVersionAllowed instead
9-
PHP_CS_FIXER_PARALLEL= # `0` / `1`, default is `0` - run PHP CS Fixer in parallel mode; use Config::setParallelConfig instead
9+
PHP_CS_FIXER_PARALLEL= # no effect; use Config::setParallelConfig instead
1010

1111
## @internal
1212
PHP_CS_FIXER_ENFORCE_CACHE= # `0` / `1`, default is `0` - enforce cache usage

.php-cs-fixer.dist.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PhpCsFixer\Finder;
1717
use PhpCsFixer\Fixer\Internal\ConfigurableFixerTemplateFixer;
1818
use PhpCsFixer\RuleSet\Sets\Internal\InternalRiskySet;
19-
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
2019

2120
if (
2221
filter_var(getenv('PHP_CS_FIXER_TESTS_SYSTEM_UNDER_TEST'), \FILTER_VALIDATE_BOOL)
@@ -41,7 +40,6 @@
4140
];
4241

4342
return (new Config())
44-
->setParallelConfig(ParallelConfigFactory::detect()) // @TODO 4.0 no need to call this manually
4543
->setUnsupportedPhpVersionAllowed(true)
4644
->setRiskyAllowed(true)
4745
->registerCustomRuleSets([

resources/.php-cs-fixer.dist.php.template

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ declare(strict_types=1);
44

55
use PhpCsFixer\Config;
66
use PhpCsFixer\Finder;
7-
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
87

98
return (new Config())
10-
->setParallelConfig(ParallelConfigFactory::detect()) // @TODO 4.0 no need to call this manually
119
->setRiskyAllowed(/*{{ IS_RISKY_ALLOWED }}*/)
1210
->setRules(/*{{ RULES }}*/)
1311
// 💡 by default, Fixer looks for `*.php` files excluding `./vendor/` - here, you can groom this config

src/Config.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,7 @@ public function __construct(string $name = 'default')
9292
$this->name = $name.(Future::isFutureModeEnabled() ? ' (future mode)' : '');
9393
$this->rules = Future::getV4OrV3(['@PER-CS' => true], ['@PSR12' => true]); // @TODO 4.0 | 3.x switch to '@auto' for v4
9494
$this->format = Future::getV4OrV3('@auto', 'txt');
95-
96-
// @TODO 4.0 cleanup
97-
if (Future::isFutureModeEnabled() || filter_var(getenv('PHP_CS_FIXER_PARALLEL'), \FILTER_VALIDATE_BOOL)) {
98-
$this->parallelConfig = ParallelConfigFactory::detect();
99-
} else {
100-
$this->parallelConfig = ParallelConfigFactory::sequential();
101-
}
95+
$this->parallelConfig = ParallelConfigFactory::detect();
10296

10397
// @TODO 4.0 cleanup
10498
if (false !== getenv('PHP_CS_FIXER_IGNORE_ENV')) {

src/Console/Command/FixCommand.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@
3030
use PhpCsFixer\FixerFactory;
3131
use PhpCsFixer\RuleSet\RuleSets;
3232
use PhpCsFixer\Runner\Event\FileProcessed;
33-
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
3433
use PhpCsFixer\Runner\Runner;
3534
use PhpCsFixer\ToolInfoInterface;
3635
use Symfony\Component\Console\Attribute\AsCommand;
3736
use Symfony\Component\Console\Command\Command;
38-
use Symfony\Component\Console\Formatter\OutputFormatter;
3937
use Symfony\Component\Console\Input\ArrayInput;
4038
use Symfony\Component\Console\Input\InputArgument;
4139
use Symfony\Component\Console\Input\InputInterface;
@@ -347,23 +345,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
347345
) : ' sequentially',
348346
));
349347

350-
/** @TODO v4 remove warnings related to parallel runner */
351-
$availableMaxProcesses = ParallelConfigFactory::detect()->getMaxProcesses();
352-
if ($isParallel || $availableMaxProcesses > 1) {
353-
$usageDocs = 'https://cs.symfony.com/doc/usage.html';
354-
$stdErr->writeln(\sprintf(
355-
$stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s',
356-
$isParallel
357-
? 'Parallel runner is an experimental feature and may be unstable, use it at your own risk. Feedback highly appreciated!'
358-
: \sprintf(
359-
'You can enable parallel runner and speed up the analysis! Please see %s for more information.',
360-
$stdErr->isDecorated()
361-
? \sprintf('<href=%s;bg=yellow;fg=red;bold>usage docs</>', OutputFormatter::escape($usageDocs))
362-
: $usageDocs,
363-
),
364-
));
365-
}
366-
367348
if ($resolver->getUsingCache()) {
368349
$cacheFile = $resolver->getCacheFile();
369350

src/Runner/Runner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static function (array $carry, FixerInterface $fixer): array {
164164
$this->cacheManager = $cacheManager;
165165
$this->directory = $directory ?? new Directory('');
166166
$this->stopOnViolation = $stopOnViolation;
167-
$this->parallelConfig = $parallelConfig ?? ParallelConfigFactory::sequential();
167+
$this->parallelConfig = $parallelConfig ?? ParallelConfigFactory::detect();
168168
$this->input = $input;
169169
$this->configFile = $configFile;
170170
$this->ruleCustomisationPolicy = $ruleCustomisationPolicy ?? new NullRuleCustomisationPolicy();

tests/ConfigTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use PhpCsFixer\Fixer\ControlStructure\IncludeFixer;
2626
use PhpCsFixer\Fixer\FixerInterface;
2727
use PhpCsFixer\Runner\Parallel\ParallelConfig;
28+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
2829
use PhpCsFixer\Tests\Fixtures\ExternalRuleSet\ExampleRuleSet;
2930
use PhpCsFixer\ToolInfo;
3031
use Symfony\Component\Console\Output\OutputInterface;
@@ -321,8 +322,9 @@ public function testConfigConstructorWithName(): void
321322
public function testConfigWithDefaultParallelConfig(): void
322323
{
323324
$config = new Config();
325+
$defaultParallelConfig = ParallelConfigFactory::detect();
324326

325-
self::assertSame(1, $config->getParallelConfig()->getMaxProcesses());
327+
self::assertSame($defaultParallelConfig->getMaxProcesses(), $config->getParallelConfig()->getMaxProcesses());
326328
}
327329

328330
public function testConfigWithExplicitParallelConfig(): void

tests/Console/Command/FixCommandTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use PhpCsFixer\Console\Application;
2020
use PhpCsFixer\Console\Command\FixCommand;
2121
use PhpCsFixer\Console\ConfigurationResolver;
22-
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
2322
use PhpCsFixer\Tests\TestCase;
2423
use PhpCsFixer\ToolInfo;
2524
use Symfony\Component\Console\Command\Command;
@@ -104,12 +103,7 @@ public function testSequentialRun(): void
104103
],
105104
);
106105

107-
$availableMaxProcesses = ParallelConfigFactory::detect()->getMaxProcesses();
108-
109106
self::assertStringContainsString('Running analysis on 1 core sequentially.', $cmdTester->getDisplay());
110-
if ($availableMaxProcesses > 1) {
111-
self::assertStringContainsString('You can enable parallel runner and speed up the analysis!', $cmdTester->getDisplay());
112-
}
113107
self::assertStringContainsString('(header_comment)', $cmdTester->getDisplay());
114108
self::assertSame(8, $cmdTester->getStatusCode());
115109
}
@@ -145,7 +139,6 @@ public function testParallelRun(): void
145139
);
146140

147141
self::assertStringContainsString('Running analysis on 2 cores with 1 file per process.', $cmdTester->getDisplay());
148-
self::assertStringContainsString('Parallel runner is an experimental feature and may be unstable, use it at your own risk. Feedback highly appreciated!', $cmdTester->getDisplay());
149142
self::assertStringContainsString('(header_comment)', $cmdTester->getDisplay());
150143
self::assertSame(8, $cmdTester->getStatusCode());
151144
}

tests/Console/ConfigurationResolverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public function testResolveParallelConfig(): void
6767
self::assertSame($parallelConfig, $resolver->getParallelConfig());
6868
}
6969

70-
public function testDefaultParallelConfigFallbacksToSequential(): void
70+
public function testDefaultParallelConfigFallbacksToAutoDetect(): void
7171
{
7272
$parallelConfig = $this->createConfigurationResolver([])->getParallelConfig();
73-
$defaultParallelConfig = ParallelConfigFactory::sequential();
73+
$defaultParallelConfig = ParallelConfigFactory::detect();
7474

7575
self::assertSame($defaultParallelConfig->getMaxProcesses(), $parallelConfig->getMaxProcesses());
7676
self::assertSame($defaultParallelConfig->getFilesPerProcess(), $parallelConfig->getFilesPerProcess());

tests/Fixtures/.php-cs-fixer.parallel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
\PhpCsFixer\Finder::create()
66
->in(__DIR__ . '/../../')
77
)
8-
->setParallelConfig(\PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()) // @TODO 4.0 no need to call this manually
8+
->setParallelConfig(new \PhpCsFixer\Runner\Parallel\ParallelConfig(10))
99
;

0 commit comments

Comments
 (0)