Completed
Push — master ( e96f63...7cd0ea )
by Rob
02:01
created

SoteriaFactory::getRulePrefixes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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