Skip to content

Commit b142bf3

Browse files
authored
Merge pull request #40 from boundwize/refactor-move-is-parallel
refactor: move parallel logic different to isParallel()
2 parents afb6eae + 67439dd commit b142bf3

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

src/Analyser/AnalyserOptions.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Fidry\CpuCoreCounter\CpuCoreCounter;
88

9+
use function function_exists;
910
use function max;
1011

1112
final readonly class AnalyserOptions
@@ -31,6 +32,10 @@ public static function parallel(?int $workerCount = null): self
3132

3233
public function isParallel(): bool
3334
{
34-
return $this->workerCount > 1;
35+
if ($this->workerCount <= 1) {
36+
return false;
37+
}
38+
39+
return function_exists('proc_open');
3540
}
3641
}

src/Analyser/Parallel/ParallelClassNodeExtractor.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
namespace Boundwize\StructArmed\Analyser\Parallel;
66

7-
use Boundwize\StructArmed\Analyser\AnalyserOptions;
87
use Boundwize\StructArmed\Analyser\ClassNode;
9-
use Boundwize\StructArmed\Analyser\ClassNodeExtractor;
10-
use Boundwize\StructArmed\LayerResolver\ChainLayerResolver;
118
use Boundwize\StructArmed\Progress\ProgressHandlerInterface;
129
use RuntimeException;
1310

@@ -23,7 +20,6 @@
2320
use function feof;
2421
use function file_put_contents;
2522
use function fread;
26-
use function function_exists;
2723
use function is_array;
2824
use function is_dir;
2925
use function is_resource;
@@ -45,8 +41,6 @@
4541

4642
final readonly class ParallelClassNodeExtractor
4743
{
48-
private AnalyserOptions $analyserOptions;
49-
5044
/**
5145
* @param array<string, string|list<string>> $layers
5246
* @param array<string, array{pattern: string, excludePattern: string|null}> $layerPatterns
@@ -58,7 +52,6 @@ public function __construct(
5852
private int $workerCount,
5953
private ?string $cacheDirectory = null,
6054
) {
61-
$this->analyserOptions = AnalyserOptions::parallel($this->workerCount);
6255
}
6356

6457
/**
@@ -67,8 +60,8 @@ public function __construct(
6760
*/
6861
public function extract(array $files, ?ProgressHandlerInterface $progressHandler = null): array
6962
{
70-
if ($files === [] || ! $this->analyserOptions->isParallel() || ! function_exists('proc_open')) {
71-
return (new ClassNodeExtractor($this->layerResolver()))->extract($files, $progressHandler);
63+
if ($files === []) {
64+
return [];
7265
}
7366

7467
$workerCount = min($this->workerCount, count($files));
@@ -257,11 +250,6 @@ private function temporaryFile(): string
257250
return $file;
258251
}
259252

260-
private function layerResolver(): ChainLayerResolver
261-
{
262-
return ChainLayerResolver::fromLayerConfig($this->layers, $this->basePath, $this->layerPatterns);
263-
}
264-
265253
/**
266254
* @param list<string> $files
267255
*/

0 commit comments

Comments
 (0)