Passed
Push — master ( 7ca88e...9f8c4e )
by Mariano
04:25
created

ArrayToExpectationConverterLocator::locate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.1755

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
nc 4
nop 1
dl 0
loc 13
ccs 7
cts 9
cp 0.7778
crap 4.1755
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Mcustiel\Phiremock\Common\Utils;
4
5
use Mcustiel\Phiremock\Common\Utils\V1\Factory as FactoryV1;
6
use Mcustiel\Phiremock\Common\Utils\V2\Factory as FactoryV2;
7
8
class ArrayToExpectationConverterLocator
9
{
10
    /** @var FactoryV1 */
11
    private $factoryV1;
12
13
    /** @var FactoryV2 */
14
    private $factoryV2;
15
16 24
    public function __construct(FactoryV1 $factoryV1, FactoryV2 $factoryV2)
17
    {
18 24
        $this->factoryV1 = $factoryV1;
19 24
        $this->factoryV2 = $factoryV2;
20 24
    }
21
22 24
    public function locate(array $expectationArray): ArrayToExpectationConverter
23
    {
24 24
        if (isset($expectationArray['version'])) {
25 15
            switch ($expectationArray['version']) {
26 15
                case '1':
27
                    return $this->factoryV1->createArrayToExpectationConverter();
28 15
                case '2':
29 15
                    return $this->factoryV2->createArrayToExpectationConverter();
30
            }
31
            throw new \Exception(sprintf('Unimplemented configuration version: %s', $expectationArray['version']));
32
        }
33
34 9
        return $this->factoryV1->createArrayToExpectationConverter();
35
    }
36
}
37