Completed
Push — master ( 6aec97...01562b )
by Derek Stephen
01:48
created

CountryFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 61.53%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 39
ccs 8
cts 13
cp 0.6153
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __clone() 0 3 1
A generate() 0 11 2
A setCountryRepository() 0 4 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
    /**
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
        return $inst->countryRepository->findCountryByIsoCode($id);
37
    }
38
39
    /**
40
     * @param CountryRepository $countryRepository
41
     */
42
    public function setCountryRepository(CountryRepository $countryRepository): void
43
    {
44
        $this->countryRepository = $countryRepository;
45
    }
46
}
47