Skip to content

Commit eb890af

Browse files
Allow setting the number of max processes for parallel mode (#392)
* max processes * simplify * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 06dca19 commit eb890af

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

app/Actions/FixCode.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Factories\ConfigurationResolverFactory;
66
use LaravelZero\Framework\Exceptions\ConsoleException;
77
use PhpCsFixer\Console\ConfigurationResolver;
8+
use PhpCsFixer\Runner\Parallel\ParallelConfig;
89
use PhpCsFixer\Runner\Runner;
910
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Input\InputOption;
@@ -62,15 +63,35 @@ public function execute()
6263
$resolver->getCacheManager(),
6364
$resolver->getDirectory(),
6465
$resolver->shouldStopOnViolation(),
65-
$resolver->getParallelConfig(),
66+
$this->getParallelConfig($resolver),
6667
$this->getInput($resolver),
6768
));
6869

6970
return tap([$totalFiles, $changes], fn () => $this->progress->unsubscribe());
7071
}
7172

7273
/**
73-
* Gets the input for the PHP CS Fixer Runner.
74+
* Get the ParallelConfig for the number of cores.
75+
*/
76+
private function getParallelConfig(ConfigurationResolver $resolver): ParallelConfig
77+
{
78+
$maxProcesses = intval($this->input->getOption('max-processes') ?? 0);
79+
80+
if (! $this->input->getOption('parallel') || $maxProcesses < 1) {
81+
return $resolver->getParallelConfig();
82+
}
83+
84+
$parallelConfig = $resolver->getParallelConfig();
85+
86+
return new ParallelConfig(
87+
$maxProcesses,
88+
$parallelConfig->getFilesPerProcess(),
89+
$parallelConfig->getProcessTimeout()
90+
);
91+
}
92+
93+
/**
94+
* Get the input for the PHP CS Fixer Runner.
7495
*/
7596
private function getInput(ConfigurationResolver $resolver): InputInterface
7697
{

app/Commands/DefaultCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function configure()
5050
new InputOption('output-format', '', InputOption::VALUE_REQUIRED, 'The format that should be used when outputting the test results to a file'),
5151
new InputOption('cache-file', '', InputArgument::OPTIONAL, 'The path to the cache file'),
5252
new InputOption('parallel', 'p', InputOption::VALUE_NONE, 'Runs the linter in parallel (Experimental)'),
53+
new InputOption('max-processes', null, InputOption::VALUE_REQUIRED, 'The number of processes to spawn when using parallel execution'),
5354
],
5455
);
5556
}

0 commit comments

Comments
 (0)