Passed
Push — master ( 227996...93e4af )
by Derek Stephen
10:29
created

CountryFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 8
c 3
b 0
f 0
dl 0
loc 34
ccs 5
cts 7
cp 0.7143
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 10 2
A __construct() 0 2 1
A __clone() 0 2 1
A setCountryRepository() 0 3 1
1
<?php
2
3
namespace Del\Factory;
4
5
use Del\Entity\Country;
6
use Del\Repository\CountryRepository;
7
8
class CountryFactory
9
{
10
    private CountryRepository $countryRepository;
11
12
    private function __construct()
13
    {
14
    }
15
16
    private function __clone()
17
    {
18
    }
19
20
    /**
21
     * @param string $id
22
     * @return Country
23
     */
24 3
    public static function generate(string $id): Country
25
    {
26
        static $inst = null;
27
28 3
        if ($inst === null) {
29 1
            $inst = new CountryFactory();
30 1
            $inst->countryRepository = new CountryRepository();
31
        }
32
33 3
        return $inst->countryRepository->findCountryByIsoCode($id);
34
    }
35
36
    /**
37
     * @param CountryRepository $countryRepository
38
     */
39
    public function setCountryRepository(CountryRepository $countryRepository): void
40
    {
41
        $this->countryRepository = $countryRepository;
42
    }
43
}
44