Passed
Branch develop (905d13)
by Mariano
09:27
created

ConditionsMatcherFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 1
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($id)
26
    {
27 3
        if (isset($this->conditionMatchersMap[$id])) {
28 3
            return new $this->conditionMatchersMap[$id](
29 3
                $this->inputSouceFactory,
30 3
                $this->matcherFactory
31 3
            );
32
        }
33
        throw new \RuntimeException('Invalid condition matcher specified');
34
    }
35
}
36