Completed
Push — master ( 7bccf6...d15e2a )
by Rob
01:53
created

SoteriaFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 29
ccs 8
cts 11
cp 0.7272
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRulePrefixes() 0 4 1
A build() 0 16 3
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