Handler::build()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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