Legislature   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 93.1%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 2
cbo 2
dl 0
loc 83
ccs 27
cts 29
cp 0.931
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 3
A __toString() 0 4 1
A directory() 0 6 1
A popolo() 0 4 1
A legislativePeriods() 0 8 2
1
<?php
2
3
namespace EveryPolitician\EveryPolitician;
4
5
use \DateTime;
6
use \EveryPolitician\EveryPoliticianPopolo\Popolo;
7
8
class Legislature
9
{
10
    public $name;
11
    public $slug;
12
    public $personCount;
13
    public $sha;
14
    public $statementCount;
15
    public $popoloUrl;
16
    public $lastmod;
17
    protected $legislatureData;
18
    protected $country;
19
20
    /**
21
     * Creates a new instance
22
     *
23
     * @param array $legislatureData Popolo legislature data
24
     * @param Country @country country for this legislature
25
     */
26 27
    public function __construct($legislatureData, $country)
27
    {
28
        $propertyMappings = [
29 27
            'name' => 'name',
30 9
            'slug' => 'slug',
31 9
            'person_count' => 'personCount',
32 9
            'sha' => 'sha',
33 9
            'statement_count' => 'statementCount',
34
            'popolo_url' => 'popoloUrl'
35 9
        ];
36 27
        foreach ($propertyMappings as $k => $v) {
37 27
            $this->$v = array_key_exists($k, $legislatureData) ? $legislatureData[$k] : null;
38 9
        }
39 27
        $timestamp = $legislatureData['lastmod'];
40 27
        $this->lastmod = DateTime::createFromFormat('U', $timestamp);
41 27
        $this->legislatureData = $legislatureData;
42 27
        $this->country = $country;
43 27
    }
44
45
    /**
46
     * String representation of {@link Legislature}
47
     *
48
     * @return string
49
     */
50 3
    public function __toString()
51
    {
52 3
        return '<Legislature: '.$this->name.' in '.$this->country->name.'>';
53
    }
54
55
    /**
56
     * Return the directory path in the everypolitician-data repository
57
     *
58
     * @return string
59
     */
60 3
    public function directory()
61
    {
62 3
        $splitPath = explode('/', $this->legislatureData['sources_directory']);
63 3
        $splitPath = array_slice($splitPath, 1, 2);
64 3
        return implode('/', $splitPath);
65
    }
66
67
    /**
68
     * Return a Popolo instance for this {@link Legislature}
69
     *
70
     * @return Popolo
71
     */
72
    public function popolo()
73
    {
74
        return Popolo::fromUrl($this->popoloUrl);
75
    }
76
77
    /**
78
     * Return all the known legislative periods for this legislature
79
     *
80
     * @return LegislativePeriod[]
81
     */
82 9
    public function legislativePeriods()
83
    {
84 9
        $legislativePeriods = [];
85 9
        foreach ($this->legislatureData['legislative_periods'] as $lpData) {
86 9
            $legislativePeriods[] = new LegislativePeriod($lpData, $this, $this->country);
87 3
        }
88 9
        return $legislativePeriods;
89
    }
90
}
91