Completed
Push — master ( aecae1...06dd79 )
by Sébastien
01:49
created

StackCallableFactory::createCallable()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 4
nop 2
1
<?php
2
3
namespace Bdf\Pipeline\CallableFactory;
4
5
use Bdf\Pipeline\CallableFactoryInterface;
6
7
/**
8
 * StackCallableFactory
9
 *
10
 * @author Sébastien Tanneux
11
 */
12
class StackCallableFactory implements CallableFactoryInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function createCallable(array $pipes, callable $outlet = null)
18
    {
19
        if ($outlet !== null) {
20
            $callable = $outlet;
21
        } else {
22
            $callable = function ($payload) {
23
                return $payload;
24
            };
25
        };
26
27
        while ($pipe = array_pop($pipes)) {
28
            $callable = function (...$payload) use ($pipe, $callable) {
29
                return $pipe($callable, ...$payload);
30
            };
31
        }
32
33
        return $callable;
34
    }
35
}
36