ConditionsMatcherFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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