Skip to content

Commit

Permalink
fix: Runner - handle no files while in parallel runner (#8015)
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed May 15, 2024
1 parent 4f69067 commit 3810546
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Runner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,28 @@ public function __construct(
}

/**
* @TODO consider to drop this method and make iterator parameter obligatory in constructor,
* more in https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7777/files#r1590447581
*
* @param \Traversable<array-key, \SplFileInfo> $fileIterator
*/
public function setFileIterator(iterable $fileIterator): void
{
// @TODO consider to drop this method and make iterator parameter obligatory in constructor,
// more in https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7777/files#r1590447581
$this->fileIterator = $fileIterator;

// Required only for main process (calculating workers count)
$this->fileCount = \count(iterator_to_array($fileIterator));
}

/**
* @return _RunResult
*/
public function fix(): array
{
if (0 === $this->fileCount) {
return [];
}

// @TODO Remove condition for the input argument in 4.0, as it should be required in the constructor
return $this->parallelConfig->getMaxProcesses() > 1 && null !== $this->input
? $this->fixParallel()
Expand Down Expand Up @@ -222,7 +230,10 @@ private function fixParallel(): array

$processesToSpawn = min(
$this->parallelConfig->getMaxProcesses(),
(int) ceil($this->fileCount / $this->parallelConfig->getFilesPerProcess())
max(
1,
(int) ceil($this->fileCount / $this->parallelConfig->getFilesPerProcess()),
)
);
$processFactory = new ProcessFactory($this->input);

Expand Down

0 comments on commit 3810546

Please sign in to comment.