Handler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
}