Passed
Push — master ( 9534e6...9c83c0 )
by Rob
02:17
created

Handler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 27.27%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 24
ccs 3
cts 11
cp 0.2727
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A build() 0 15 3
1
<?php
2
3
namespace devtoolboxuk\cerberus\Handlers;
4
5
use ReflectionClass;
6
7
use Exception;
8
9
class Handler extends AbstractBase
10
{
11
12 4
    public function __construct($value)
13
    {
14 4
        parent::__construct($value);
15 4
    }
16
17
18
    public function build($method, $arguments = [])
19
    {
20
        $className = __NAMESPACE__ . '\\' . ucfirst($method) . 'Handler';
21
22
        if (class_exists($className)) {
23
24
            $reflection = new ReflectionClass($className);
25
26
            if (!$reflection->isInstantiable()) {
27
                throw new Exception(sprintf('"%s" must be instantiable', $className));
28
            }
29
30
            return $reflection->newInstanceArgs($arguments);
31
        }
32
        throw new Exception(sprintf('"%s" is not a valid rule name', $method));
33
    }
34
35
}