Completed
Push — master ( 21c42f...4669bc )
by Alessandro
14s
created

Pipeline::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace AlexManno\Remix\Pipelines;
4
5
use AlexManno\Remix\Pipelines\Interfaces\PipelineInterface;
6
use AlexManno\Remix\Pipelines\Interfaces\StageInterface;
7
use AlexManno\Remix\Pipelines\Interfaces\PayloadInterface;
8
use SplQueue;
9
10
class Pipeline implements PipelineInterface
11
{
12
    /** @var SplQueue */
13
    private $stages;
14
15
    /**
16
     * Pipeline constructor.
17
     */
18 5
    public function __construct()
19
    {
20 5
        $this->stages = new SplQueue();
21 5
    }
22
23 5
    public function pipe(StageInterface $stage): PipelineInterface
24
    {
25 5
        $this->stages->enqueue($stage);
26
27 5
        return $this;
28
    }
29
30 1
    public function getStages(): \SplQueue
31
    {
32 1
        return $this->stages;
33
    }
34
35 1
    public function add(PipelineInterface $pipeline): PipelineInterface
36
    {
37 1
        $queue = $pipeline->getStages();
38
39 1
        $queue->rewind();
40 1
        while ($queue->valid()) {
41 1
            $this->stages->enqueue($queue->current());
42 1
            $queue->next();
43
        }
44
45 1
        return $this;
46
    }
47
48 2
    public function count(): int
49
    {
50 2
        return $this->stages->count();
51
    }
52
53 3
    public function __invoke(PayloadInterface $payload): PayloadInterface
54
    {
55 3
        $this->stages->rewind();
56 3
        while ($this->stages->valid()) {
57 3
            $payload = $this->stages->current()($payload);
58 3
            $this->stages->next();
59
        }
60
61 3
        return $payload;
62
    }
63
}
64