Passed
Push — master ( 457a90...753c96 )
by Sébastien
02:13
created

Pipe::getNext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bdf\Pipeline\Pipe;
4
5
use Bdf\Pipeline\PipeInterface;
6
use Bdf\Pipeline\ProcessorInterface;
7
8
/**
9
 * A pipe
10
 *
11
 * @internal
12
 *
13
 * @author Sébastien Tanneux
14
 */
15
final class Pipe implements PipeInterface
16
{
17
    /**
18
     * The callback processor
19
     *
20
     * @var ProcessorInterface
21
     */
22
    private $processor;
23
24
    /**
25
     * The pipe callback
26
     *
27
     * @var callable
28
     */
29
    private $callback;
30
31
    /**
32
     * The pipe chain
33
     *
34
     * @var callable
35
     */
36
    private $next;
37
38
    /**
39
     * Pipe constructor
40
     *
41
     * @param ProcessorInterface $processor
42
     * @param callable $callback
43
     */
44
    public function __construct(ProcessorInterface $processor, callable $callback)
45
    {
46
        $this->processor = $processor;
47
        $this->callback = $callback;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function setNext(callable $pipe)
54
    {
55
        $this->next = $pipe;
56
    }
57
58
    /**
59
     * Get the next pipe
60
     *
61
     * @return callable
62
     */
63
    public function getNext()
64
    {
65
        return $this->next;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function __invoke(...$payload)
72
    {
73
        return $this->processor->process($this->callback, $payload, $this->next);
74
    }
75
76
    /**
77
     * Clone the pipe
78
     */
79
    public function __clone()
80
    {
81
        if ($this->next instanceof PipeInterface) {
82
            $this->next = clone $this->next;
83
        }
84
    }
85
}
86