ChainHandler::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3
Metric Value
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
cc 3
eloc 5
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Chainable\Handler;
4
5
use Chainable\ChainableInterface;
6
7
final class ChainHandler implements ChainHandlerInterface
8
{
9
    /**
10
     * @var ChainableInterface[]
11
     */
12
    private $chain = [];
13
14
    /**
15
     * @param ChainableInterface $chainable
16
     *
17
     * @return $this
18
     */
19 3
    public function append(ChainableInterface $chainable)
20
    {
21 3
        $this->chain[] = $chainable;
22
23 3
        return $this;
24
    }
25
26
    /**
27
     * @param callable $data
28
     *
29
     * @return mixed|null
30
     */
31 3
    public function process(... $data)
32
    {
33 3
        foreach ($this->chain as $chain) {
34 3
            $result = $chain->process($data);
35 3
            if ($result->isSuccess()) {
36 2
                return $result->getData();
37
            }
38 2
        }
39 1
    }
40
}
41