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

StackCallableFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createCallable() 0 17 3
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