Completed
Push — master ( 1f9a47...783c9c )
by Sébastien
02:13
created

LinkedCallableFactory::callPipeline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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