Completed
Push — master ( a17288...aa8e2a )
by Derek Stephen
01:49
created

CountryFactory::setCountryRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Del\Factory;
4
5
use Del\Entity\Country;
6
use Del\CountryException;
7
use Del\Repository\CountryRepository;
8
9
class CountryFactory
10
{
11
    /**
12
     * @var CountryRepository $countryRepository
13
     */
14
    private $countryRepository;
15
16 1
    private function __construct()
17
    {
18 1
    }
19
20
    private function __clone()
21
    {
22
    }
23
24
    /**
25
     * @param string $id
26
     * @return Country
27
     */
28 3
    public static function generate(string $id): Country
29
    {
30 3
        static $inst = null;
31
32 3
        if ($inst === null) {
33 1
            $inst = new CountryFactory();
34 1
            $inst->countryRepository = new CountryRepository();
35
        }
36
37 3
        $data = $inst->countryRepository->findCountryByIsoCode($id);
38
39
        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...
40
    }
41
42
    /**
43
     * @param CountryRepository $countryRepository
44
     */
45
    public function setCountryRepository(CountryRepository $countryRepository): void
46
    {
47
        $this->countryRepository = $countryRepository;
48
    }
49
}
50