Completed
Push — master ( 675c0a...658806 )
by Andy
03:18
created

Legislature   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 2
cbo 1
dl 0
loc 51
ccs 23
cts 23
cp 1
rs 10

4 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
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
    public function __construct($legislatureData, $country)
21
    {
22
        $propertyMappings = [
23 21
            'name' => 'name',
24 14
            'slug' => 'slug',
25 14
            'person_count' => 'personCount',
26 14
            'sha' => 'sha',
27 14
            'statement_count' => 'statementCount',
28
            'popolo_url' => 'popoloUrl'
29 14
        ];
30 21
        foreach ($propertyMappings as $k => $v) {
31 21
            $this->$v = array_key_exists($k, $legislatureData) ? $legislatureData[$k] : null;
32 14
        }
33 21
        $timestamp = $legislatureData['lastmod'];
34 21
        $this->lastmod = DateTime::createFromFormat('U', $timestamp);
35 21
        $this->legislatureData = $legislatureData;
36 21
        $this->country = $country;
37 21
    }
38
39 3
    public function __toString()
40
    {
41 3
        return '<Legislature: '.$this->name.' in '.$this->country->name.'>';
42
    }
43
44
    /**
45
     * Return the directory path in the everypolitician-data repository
46
     */
47 3
    public function directory()
48
    {
49 3
        $splitPath = explode('/', $this->legislatureData['sources_directory']);
50 3
        $splitPath = array_slice($splitPath, 1, 2);
51 3
        return implode('/', $splitPath);
52
    }
53
54 3
    public function popolo()
55
    {
56 3
        return Popolo::fromUrl($this->popoloUrl);
57
    }
58
}
59