Completed
Push — master ( 34418f...bffe6c )
by Sébastien
01:55
created

Pipe::__clone()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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