Completed
Push — master ( 472029...d7e60d )
by Andy
01:48
created

Legislature   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 45
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 3
A __toString() 0 4 1
A directory() 0 6 1
1
<?php
2
3
namespace EveryPolitician\EveryPolitician;
4
5
class Legislature
6
{
7
    public $name;
8
    public $slug;
9
    public $personCount;
10
    public $sha;
11
    public $statementCount;
12
    public $popoloUrl;
13
    protected $legislatureData;
14
    protected $country;
15
16 18
    public function __construct($legislatureData, $country)
17
    {
18
        $propertyMappings = [
19 18
            'name' => 'name',
20 12
            'slug' => 'slug',
21 12
            'person_count' => 'personCount',
22 12
            'sha' => 'sha',
23 12
            'statement_count' => 'statementCount',
24
            'popolo_url' => 'popoloUrl'
25 12
        ];
26 18
        foreach ($propertyMappings as $k => $v) {
27 18
            $this->$v = array_key_exists($k, $legislatureData) ? $legislatureData[$k] : null;
28 12
        }
29 18
        $timestamp = $legislatureData['lastmod'];
30 18
        $this->lastmod = \DateTime::createFromFormat('U', $timestamp);
0 ignored issues
show
Bug introduced by
The property lastmod does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31 18
        $this->legislatureData = $legislatureData;
32 18
        $this->country = $country;
33 18
    }
34
35 3
    public function __toString()
36
    {
37 3
        return '<Legislature: '.$this->name.' in '.$this->country->name.'>';
38
    }
39
40
    /**
41
     * Return the directory path in the everypolitician-data repository
42
     */
43 3
    public function directory()
44
    {
45 3
        $splitPath = explode('/', $this->legislatureData['sources_directory']);
46 3
        $splitPath = array_slice($splitPath, 1, 2);
47 3
        return implode('/', $splitPath);
48
    }
49
}
50