Completed
Push — master ( 718bf1...6aec97 )
by Derek Stephen
01:41
created

CountryFactory::generate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Del\Factory;
4
5
use Del\Entity\Country;
6
use Del\Repository\CountryRepository;
7
8
class CountryFactory
9
{
10
    /**
11
     * @var CountryRepository $countryRepository
12
     */
13
    private $countryRepository;
14
15 1
    private function __construct()
16
    {
17 1
    }
18
19
    private function __clone()
20
    {
21
    }
22
23
    /**
24
     * @param string $id
25
     * @return Country
26
     */
27 3
    public static function generate(string $id): Country
28
    {
29 3
        static $inst = null;
30
31 3
        if ($inst === null) {
32 1
            $inst = new CountryFactory();
33 1
            $inst->countryRepository = new CountryRepository();
34
        }
35
36 3
        $data = $inst->countryRepository->findCountryByIsoCode($id);
37
38 2
        return  $inst->countryRepository->createFromArray($data);
0 ignored issues
show
Documentation introduced by
$data is of type object<Del\Entity\Country>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
    }
40
41
    /**
42
     * @param CountryRepository $countryRepository
43
     */
44
    public function setCountryRepository(CountryRepository $countryRepository): void
45
    {
46
        $this->countryRepository = $countryRepository;
47
    }
48
}
49