Completed
Push — master ( 4ce326...4e987e )
by Derek Stephen
03:42 queued 02:43
created

CountryFactory::generate()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 1
dl 0
loc 26
ccs 18
cts 18
cp 1
crap 3
rs 9.504
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: delboy1978uk
4
 * Date: 30/10/15
5
 * Time: 16:34
6
 */
7
8
namespace Del\Factory;
9
10
use Del\Entity\Country;
11
use InvalidArgumentException;
12
13
class CountryFactory
14
{
15
    private $countries;
16
17
    public function __construct(){}
18
    public function __clone(){}
19
20
    /**
21
     * @param string $id
22
     * @return Country
23
     */
24 3
    public static function generate($id)
25
    {
26 3
        static $inst = null;
27 3
        if($inst === null)
28 3
        {
29 1
            $inst = new CountryFactory();
30 1
            $inst->countries = require('countries.php');
31 1
        }
32
33 3
        if(!isset($inst->countries[$id])) {
34 1
            throw new InvalidArgumentException('No country found with that ID');
35
        }
36
37 2
        $c = $inst->countries[$id];
38
39
40 2
        $country = new Country();
41 2
        $country->setId($c['id'])
42 2
            ->setIso($c['iso'])
43 2
            ->setName($c['name'])
44 2
            ->setCountry($c['country'])
45 2
            ->setNumCode($c['numcode'])
46 2
            ->setFlag($c['flag']);
47
48 2
        return $country;
49
    }
50
}