| Total Complexity | 6 |
| Total Lines | 68 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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() |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 |