Pipeline::flow()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Ghc\Rosetta;
4
5
use Ghc\Rosetta\Pipes\Pipeable;
6
7
class Pipeline
8
{
9
    use Configurable;
10
11
    /**
12
     * @var \Closure[]
13
     */
14
    protected $pipes = [];
15
16
    /**
17
     * Pipeline constructor.
18
     *
19
     * @param array $config
20
     */
21
    public function __construct($config = [])
22
    {
23
        $this->setConfig($config);
24
    }
25
26
    public function pushPipe($pipe, $options = [])
27
    {
28
        if ($pipe instanceof Pipeable) {
29
            $this->pipes[] = $pipe->pipe($options);
30
        } elseif ($pipe instanceof \Closure) {
31
            $this->pipes[] = $pipe;
32
        }
33
34
        return $this;
35
    }
36
37
    public function flow($data = null)
38
    {
39
        foreach ($this->pipes as $pipe) {
40
            /** @var \Closure $pipe */
41
            $data = $pipe($data);
42
        }
43
44
        return $data;
45
    }
46
}
47