Completed
Push — master ( d15e2a...9605ab )
by Rob
01:57
created

SoteriaFactory::getRulePrefixes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
    public function build($ruleName)
14
    {
15
16
        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
            $className = $prefix . ucfirst($ruleName);
19
            if (!class_exists($className)) {
20
                continue;
21
            }
22
23
            $reflection = new ReflectionClass($className);
24
            return $reflection->newInstance();
25
        }
26
27
        throw new \Exception(sprintf('"%s" is not a valid handler name', $ruleName));
28
    }
29
30
    public function getRulePrefixes()
31
    {
32
        return $this->rulePrefixes;
33
    }
34
35
}
36