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

Person::displayChamber()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 12
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
c 1
b 0
f 0
nc 5
nop 0
dl 0
loc 12
rs 9.6111
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