Completed
Push — master ( 74ffa0...ed410a )
by Mariano
10:21
created

ConditionsMatcherFactory::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 10
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2.0116
1
<?php
2
namespace Mcustiel\PowerRoute\Common\Conditions;
3
4
use Mcustiel\PowerRoute\Common\Factories\InputSourceFactory;
5
use Mcustiel\PowerRoute\Common\Factories\MatcherFactory;
6
7
class ConditionsMatcherFactory
8
{
9
    private $conditionMatchersMap = [
10
        'allConditionsMatcher' => AllConditionsMatcher::class,
11
        'oneConditionsMatcher' => OneConditionMatcher::class
12
    ];
13
14
    private $inputSouceFactory;
15
    private $matcherFactory;
16
17 3
    public function __construct(
18
        InputSourceFactory $inputSouceFactory,
19
        MatcherFactory $matcherFactory
20
    ) {
21 3
        $this->inputSouceFactory = $inputSouceFactory;
22 3
        $this->matcherFactory = $matcherFactory;
23 3
    }
24
25 3
    public function get($name)
26
    {
27 3
        if (isset($this->conditionMatchersMap[$name])) {
28 3
            return new $this->conditionMatchersMap[$name](
29 3
                $this->inputSouceFactory,
30 3
                $this->matcherFactory
31 3
            );
32
        }
33
        throw new \RuntimeException('Invalid condition matcher specified');
34
    }
35
}
36