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

ArrayToExpectationConverterLocator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 27
ccs 11
cts 13
cp 0.8462
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A locate() 0 13 4
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