ChainHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 34
wmc 4
lcom 1
cbo 2
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A append() 0 6 1
A process() 0 9 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