ChainHandler::append()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
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