Passed
Pull Request — master (#1856)
by
unknown
11:54
created

Person   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A displayChamber() 0 12 5
A getCategoryFromId() 0 7 3
1
<?php
2
/**
3
 * Mirrors pydantic model for deseralisation in a PHP context.
4
 * For adding display related helper functions.
5
 * @package TheyWorkForYou
6
 */
7
8
declare(strict_types=1);
9
10
namespace MySociety\TheyWorkForYou\DataClass\Regmem;
11
12
use MySociety\TheyWorkForYou\DataClass\BaseModel;
13
14
use InvalidArgumentException;
15
16
class Person extends BaseModel {
17
    public string $chamber;
18
    public string $language;
19
    public string $person_id;
20
    public string $person_name;
21
    public string $published_date;
22
    public CategoryList $categories;
23
24
    public function displayChamber(): string {
25
        switch ($this->chamber) {
26
            case 'house-of-commons':
27
                return 'House of Commons';
28
            case 'welsh-parliament':
29
                return 'Senedd';
30
            case 'scottish-parliament':
31
                return 'Scottish Parliament';
32
            case 'northern-ireland-assembly':
33
                return 'Northern Ireland Assembly';
34
            default:
35
                return 'Unknown Chamber';
36
        }
37
    }
38
39
    public function getCategoryFromId(string $categoryId): Category {
40
        foreach ($this->categories as $category) {
41
            if ($category->category_id === $categoryId) {
42
                return $category;
43
            }
44
        }
45
        throw new InvalidArgumentException("Category $categoryId not found in register");
46
    }
47
}
48