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

LinkedCallableFactory::createCallable()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 2
nop 2
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