Passed
Push — master ( 537d79...534bb6 )
by Mariano
01:14
created

ArrayToExpectationConverterLocator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 29
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A locate() 0 15 4
A __construct() 0 4 1
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
    public function __construct(FactoryV1 $factoryV1, FactoryV2 $factoryV2)
17
    {
18
        $this->factoryV1 = $factoryV1;
19
        $this->factoryV2 = $factoryV2;
20
    }
21
22
    public function locate(array $expectationArray): ArrayToExpectationConverter
23
    {
24
        if (isset($expectationArray['version'])) {
25
            switch ($expectationArray['version']) {
26
                case '1':
27
                    return $this->factoryV1->createArrayToExpectationConverter();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->factoryV1-...oExpectationConverter() returns the type Mcustiel\Phiremock\Commo...yToExpectationConverter which is incompatible with the type-hinted return Mcustiel\Phiremock\Commo...yToExpectationConverter.
Loading history...
28
                case '2':
29
                    return $this->factoryV2->createArrayToExpectationConverter();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->factoryV2-...oExpectationConverter() returns the type Mcustiel\Phiremock\Commo...yToExpectationConverter which is incompatible with the type-hinted return Mcustiel\Phiremock\Commo...yToExpectationConverter.
Loading history...
30
            }
31
            throw new \Exception(
32
                sprintf('Unimplemented configuration version: %s', $expectationArray['version'])
33
            );
34
        }
35
36
        return $this->factory->createArrayToExpectationConverterV1();
0 ignored issues
show
Bug introduced by
The property factory does not exist on Mcustiel\Phiremock\Commo...ctationConverterLocator. Did you mean factoryV2?
Loading history...
37
    }
38
}
39