PipelineCollection   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 61
ccs 23
cts 23
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A push() 0 12 3
A hasEmptySlots() 0 10 3
A isEmpty() 0 10 3
A triggerProcessTermination() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\Runner;
6
7
use Paraunit\Process\AbstractParaunitProcess;
8
9
/**
10
 * Class PipelineCollection
11
 * @package Paraunit\Runner
12
 */
13
class PipelineCollection
14
{
15
    /** @var Pipeline[] | \SplFixedArray */
16
    private $pipelines;
17
18 51
    public function __construct(PipelineFactory $pipelineFactory, int $maxProcessNumber = 10)
19
    {
20 51
        $this->pipelines = new \SplFixedArray($maxProcessNumber);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \SplFixedArray($maxProcessNumber) of type object<SplFixedArray> is incompatible with the declared type array<integer,object<Paraunit\Runner\Pipeline>> of property $pipelines.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
21
22 51
        for ($pipelineNumber = 1; $pipelineNumber <= $maxProcessNumber; ++$pipelineNumber) {
23 51
            $this->pipelines->offsetSet($pipelineNumber - 1, $pipelineFactory->create($pipelineNumber));
24
        }
25
    }
26
27
    /**
28
     * @param AbstractParaunitProcess $process
29
     * @return Pipeline
30
     * @throws \RuntimeException
31
     */
32 26
    public function push(AbstractParaunitProcess $process): Pipeline
33
    {
34 26
        foreach ($this->pipelines as $pipeline) {
35 26
            if ($pipeline->isFree()) {
36 25
                $pipeline->execute($process);
37
38 26
                return $pipeline;
39
            }
40
        }
41
42 1
        throw new \RuntimeException('Cannot find an available pipeline');
43
    }
44
45 28
    public function hasEmptySlots(): bool
46
    {
47 28
        foreach ($this->pipelines as $pipeline) {
48 28
            if ($pipeline->isFree()) {
49 28
                return true;
50
            }
51
        }
52
53 5
        return false;
54
    }
55
56 28
    public function isEmpty(): bool
57
    {
58 28
        foreach ($this->pipelines as $pipeline) {
59 28
            if (! $pipeline->isFree()) {
60 28
                return false;
61
            }
62
        }
63
64 25
        return true;
65
    }
66
67 24
    public function triggerProcessTermination()
68
    {
69 24
        foreach ($this->pipelines as $pipeline) {
70 24
            $pipeline->triggerTermination();
71
        }
72
    }
73
}
74