ProcessCollection::add()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.5923

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
ccs 8
cts 12
cp 0.6667
rs 9.2
cc 4
eloc 10
nc 4
nop 1
crap 4.5923
1
<?php
2
3
namespace SRIO\ChainOfResponsibility;
4
5
class ProcessCollection
6
{
7
    /**
8
     * @var ChainProcessInterface[]
9
     */
10
    private $processes;
11
12
    /**
13
     * Add a process to the collection.
14
     *
15
     * @param array|ChainProcessInterface $process
16
     */
17 10
    public function add($process)
18
    {
19 10
        if (is_array($process)) {
20 10
            foreach ($process as $p) {
21 9
                $this->add($p);
22 10
            }
23 10
        } elseif (!$process instanceof ChainProcessInterface) {
24
            throw new \RuntimeException(sprintf(
25
                'Expect to be instance of ChainProcessInterface or array but got %s',
26
                get_class($process)
27
            ));
28
        } else {
29 9
            $this->processes[] = $process;
30
        }
31 10
    }
32
33
    /**
34
     * @return ChainProcessInterface[]
35
     */
36 10
    public function getProcesses()
37
    {
38 10
        return $this->processes;
39
    }
40
}
41