Pipeline   A
last analyzed

↳ Parent: Project

Coupling/Cohesion

Components 1
Dependencies 2

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 63
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 4
A pipe() 0 7 1
A process() 0 4 1
A __invoke() 0 4 1
1
<?php
2
3
namespace League\Pipeline;
4
5
use InvalidArgumentException;
6
7
class Pipeline implements PipelineInterface
8
{
9
    /**
10
     * @var callable[]
11
     */
12
    private $stages = [];
13
14
    /**
15
     * @var ProcessorInterface
16
     */
17
    private $processor;
18
19
    /**
20
     * Constructor.
21
     *
22
     * @param callable[]         $stages
23
     * @param ProcessorInterface $processor
24
     *
25
     * @throws InvalidArgumentException
26
     */
27 18
    public function __construct(array $stages = [], ProcessorInterface $processor = null)
28
    {
29 18
        foreach ($stages as $stage) {
30 6
            if (false === is_callable($stage)) {
31 2
                throw new InvalidArgumentException('All stages should be callable.');
32
            }
33 16
        }
34
35 16
        $this->stages = $stages;
36 16
        $this->processor = $processor ?: new FingersCrossedProcessor;
37 16
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 8
    public function pipe(callable $stage)
43
    {
44 8
        $pipeline = clone $this;
45 8
        $pipeline->stages[] = $stage;
46
47 8
        return $pipeline;
48
    }
49
50
    /**
51
     * Process the payload.
52
     *
53
     * @param $payload
54
     *
55
     * @return mixed
56
     */
57 10
    public function process($payload)
58
    {
59 10
        return $this->processor->process($this->stages, $payload);
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65 4
    public function __invoke($payload)
66
    {
67 4
        return $this->process($payload);
68
    }
69
}
70