Passed
Push — master ( 2630eb...9b6994 )
by Struan
05:22
created

House::getCountryDetails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 27
nc 1
nop 1
dl 0
loc 34
rs 9.488
c 0
b 0
f 0
1
<?php
2
3
namespace MySociety\TheyWorkForYou\Utility;
4
5
/**
6
 * House Utilities
7
 *
8
 * Utility functions related to house types
9
 */
10
11
class House
12
{
13
    public static function house_name_to_number($name) {
14
        $name_to_number = array(
15
            'commons' => HOUSE_TYPE_COMMONS,
16
            'lords' => HOUSE_TYPE_LORDS,
17
            'scotland' => HOUSE_TYPE_SCOTLAND,
18
            'pbc' => HOUSE_TYPE_COMMONS,
19
        );
20
21
        return $name_to_number[$name];
22
    }
23
24
    public static function house_to_members($house) {
25
        $house_to_members = array(
26
            HOUSE_TYPE_COMMONS => array(
27
              'singular' => 'MP',
28
              'plural'   => 'MPs'
29
            ),
30
            HOUSE_TYPE_LORDS => array(
31
              'singular' => 'Member of the House of Lords',
32
              'plural'   => 'Members of the House of Lords'
33
            ),
34
            HOUSE_TYPE_NI => array(
35
              'singular' => 'MLA',
36
              'plural'   => 'MLAs'
37
            ),
38
            HOUSE_TYPE_SCOTLAND => array(
39
              'singular' => 'MSP',
40
              'plural'   => 'MSPs'
41
            )
42
        );
43
44
        return $house_to_members[$house];
45
    }
46
47
    public static function getCountryDetails($house) {
48
        $details = array(
49
            HOUSE_TYPE_COMMONS => array (
50
                'country' => 'UK',
51
                'assembly' => 'uk-commons',
52
                'location' => '&ndash; in the House of Commons',
53
                'cons_type' => 'WMC',
54
                'assembly_name' => 'House of Commons',
55
            ),
56
            HOUSE_TYPE_NI => array (
57
                'country' => 'NORTHERN IRELAND',
58
                'assembly' => 'ni',
59
                'location' => '&ndash; in the Northern Ireland Assembly',
60
                'cons_type' => 'NIE',
61
                'assembly_name' => 'Northern Ireland Assembly',
62
            ),
63
            HOUSE_TYPE_SCOTLAND => array (
64
                'country' => 'SCOTLAND',
65
                'assembly' => 'scotland',
66
                'location' => '&ndash; in the Scottish Parliament',
67
                'cons_type' => 'SPC',
68
                'assembly_name' => 'Scottish Parliament',
69
            ),
70
            HOUSE_TYPE_LORDS => array (
71
                'country' => 'UK',
72
                'assembly' => 'uk-lords',
73
                'location' => '&ndash; in the House of Lords',
74
                'cons_type' => '',
75
                'assembly_name' => 'House of Lords',
76
            )
77
        );
78
79
        $detail = $details[$house];
80
        return array($detail['country'], $detail['location'], $detail['assembly'], $detail['cons_type'], $detail['assembly_name']);
81
    }
82
83
    public static function majorToHouse($major) {
84
        $major_to_house = array(
85
            1 => array(1),
86
            2 => array(1),
87
            3 => array(1, 2),
88
            4 => array(1, 2),
89
            5 => array(3),
90
            6 => array(1),
91
            7 => array(4),
92
            8 => array(4),
93
            101 => array(2),
94
        );
95
96
        return $major_to_house[$major];
97
    }
98
}
99