Completed
Push — master ( 7cd0ea...1cc8fa )
by Rob
02:09
created

SoteriaFactory::build()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 6
cts 8
cp 0.75
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.1406
1
<?php
2
3
namespace devtoolboxuk\soteria;
4
5
use ReflectionClass;
6
7
class SoteriaFactory
8
{
9
    protected $rulePrefixes = [
10
        'devtoolboxuk\\soteria\\handlers\\',
11
    ];
12
13 6
    public function build($ruleName)
14
    {
15
16 6
        foreach ($this->getRulePrefixes() as $prefix) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
17
18 6
            $className = $prefix . ucfirst($ruleName);
19 6
            if (!class_exists($className)) {
20
                continue;
21
            }
22
23 6
            $reflection = new ReflectionClass($className);
24 6
            return $reflection->newInstance();
25
        }
26
27
        throw new \Exception(sprintf('"%s" is not a valid handler name', $ruleName));
28
    }
29
30 6
    public function getRulePrefixes()
31
    {
32 6
        return $this->rulePrefixes;
33
    }
34
35
}
36