Completed
Push — master ( c1b78a...571de1 )
by Andy
02:15
created

Country   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 47
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A __toString() 0 4 1
A legislatures() 0 9 2
A legislature() 0 9 3
1
<?php
2
3
namespace EveryPolitician\EveryPolitician;
4
5
// A class that represents a country from the countries.json file
6
class Country
7
{
8
    public $name;
9
    public $code;
10
    public $slug;
11
    protected $countryData;
12
13 27
    public function __construct($countryData)
14
    {
15 27
        $properties = ['name', 'code', 'slug'];
16 27
        foreach ($properties as $k) {
17 27
            $this->$k = $countryData[$k];
18 18
        }
19 27
        $this->countryData = $countryData;
20 27
    }
21
22 3
    public function __toString()
23
    {
24 3
        return '<Country: '.$this->name.'>';
25
    }
26
27
    /**
28
     * Return all the legislatures known for this country
29
     *
30
     * A legislature is a chamber of a parliament, e.g. the House of
31
     * Commons in the UK.
32
     */
33 6
    public function legislatures()
34
    {
35 6
        $legislatures = [];
36 6
        $legislaturesData = $this->countryData['legislatures'];
37 6
        foreach ($legislaturesData as $legislatureData) {
38 6
            $legislatures[] = new Legislature($legislatureData, $this);
39 4
        }
40 6
        return $legislatures;
41
    }
42
43 6
    public function legislature($legislatureSlug)
44
    {
45 6
        foreach ($this->legislatures() as $l) {
46 6
            if ($l->slug == $legislatureSlug) {
47 4
                return $l;
48
            }
49 2
        }
50 3
        throw new Exceptions\NotFoundException("Couldn't find the legislature with slug '$legislatureSlug'");
51
    }
52
}
53