Failed Conditions
Branch master (3ce7e2)
by Nick
14:43
created

Member   F

Complexity

Total Complexity 95

Size/Duplication

Total Lines 493
Duplicated Lines 0 %

Test Coverage

Coverage 27.94%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 493
rs 1.5789
ccs 76
cts 272
cp 0.2794
wmc 95

20 Methods

Rating   Name   Duplication   Size   Complexity  
A offices() 0 16 4
A image() 0 20 3
A isNew() 0 14 4
A getOtherConstituenciesString() 0 6 2
A getOfficeObject() 0 14 4
B getRegionalList() 0 46 5
B left_house_line() 0 9 5
C getEnterLeaveStrings() 0 37 8
B isDead() 0 34 6
B calculatePolicyDiffScore() 0 17 13
B getMostRecentMembership() 0 39 6
B includeOffice() 0 14 5
A entered_house_line() 0 9 4
B getRepNameForHouse() 0 18 5
C getPartyPolicyDiffs() 0 26 8
A getEntryDate() 0 10 2
B getOtherPartiesString() 0 12 5
A getLeftDate() 0 10 2
A getShortParty() 0 7 2
A getEUStance() 0 6 2

How to fix   Complexity   

Complex Class

Complex classes like Member often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Member, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Member Class
4
 *
5
 * @package TheyWorkForYou
6
 */
7
8
namespace MySociety\TheyWorkForYou;
9
10
/**
11
 * Member
12
 */
13
14
class Member extends \MEMBER {
15
16
    /**
17
     * Is Dead
18
     *
19
     * Determine if the member has died or not.
20
     *
21
     * @return boolean If the member is dead or not.
22
     */
23
24
    public function isDead() {
25
26
        $left_house = $this->left_house();
27
28
        if ($left_house) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $left_house of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
29
30
            // This member has left a house, and might be dead. See if they are.
31
32
            // Types of house to test for death.
33
            $house_types = array(
34
                HOUSE_TYPE_COMMONS,
35
                HOUSE_TYPE_LORDS,
36
                HOUSE_TYPE_SCOTLAND,
37
                HOUSE_TYPE_NI,
38
            );
39
40
            foreach ($house_types as $house_type) {
41
42
                if (in_array($house_type, $left_house) AND
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
43
                    $left_house[$house_type]['reason'] AND
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
44
                    $left_house[$house_type]['reason'] == 'Died'
45
                ) {
46
47
                    // This member has left a house because of death.
48
                    return TRUE;
49
                }
50
51
            }
52
53
        }
54
55
        // If we get this far the member hasn't left a house due to death, and
56
        // is presumably alive.
57
        return FALSE;
58
59
    }
60
61
    /*
62
     * Determine if the member is a new member of a house where new is
63
     * within the last 6 months.
64
     *
65
     * @param int house - identifier for the house, defaults to 1 for westminster
0 ignored issues
show
Bug introduced by
The type MySociety\TheyWorkForYou\house was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
66
     *
67
     * @return boolean
68
     */
69
70 1
    public function isNew($house = HOUSE_TYPE_COMMONS) {
71 1
        $date_entered = $this->getEntryDate($house);
72
73 1
        if ($date_entered) {
74 1
            $date_entered = new \DateTime($date_entered);
75 1
            $now = new \DateTime();
76
77 1
            $diff = $date_entered->diff($now);
78 1
            if ( $diff->y == 0 && $diff->m <= 6 ) {
79 1
                return TRUE;
80
            }
81 1
        }
82
83 1
        return FALSE;
84
    }
85
86
    /*
87
     * Get the date the person first entered a house. May not be for their current seat.
88
     *
89
     * @param int house - identifier for the house, defaults to 1 for westminster
90
     *
91
     * @return string - blank if no entry date for that house otherwise in YYYY-MM-DD format
92
     */
93
94 2
    public function getEntryDate($house = HOUSE_TYPE_COMMONS) {
95 2
        $date_entered = '';
96
97 2
        $entered_house = $this->entered_house($house);
98
99 2
        if ( $entered_house ) {
100 2
            $date_entered = $entered_house['date'];
101 2
        }
102
103 2
        return $date_entered;
104
    }
105
106
    /*
107
     * Get the date the person last left the house.
108
     *
109
     * @param int house - identifier for the house, defaults to 1 for westminster
110
     *
111
     * @return string - 9999-12-31 if they are still in that house otherwise in YYYY-MM-DD format
112
     */
113
114
    public function getLeftDate($house = HOUSE_TYPE_COMMONS) {
115
        $date_left = '';
116
117
        $left_house = $this->left_house($house);
118
119
        if ( $left_house ) {
120
            $date_left = $left_house['date'];
121
        }
122
123
        return $date_left;
124
    }
125
126
127
    public function getEUStance() {
128
        if (array_key_exists('eu_ref_stance', $this->extra_info())) {
129
            return $this->extra_info()['eu_ref_stance'];
130
        }
131
132
        return FALSE;
133
    }
134
135
    /**
136
    * Image
137
    *
138
    * Return a URL for the member's image.
139
    *
140
    * @return string The URL of the member's image.
141
    */
142
143
    public function image() {
144
145
        $is_lord = $this->house(HOUSE_TYPE_LORDS);
146
        if ($is_lord) {
147
            list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, 'lord');
148
        } else {
149
            list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, true);
150
        }
151
152
        // We can determine if the image exists or not by testing if size is set
153
        if ($size !== NULL) {
154
            $exists = TRUE;
155
        } else {
156
            $exists = FALSE;
157
        }
158
159
        return array(
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('url' => $i...e, 'exists' => $exists) returns the type array<string,mixed|boolean> which is incompatible with the documented return type string.
Loading history...
160
            'url' => $image,
161
            'size' => $size,
162
            'exists' => $exists
163
        );
164
165
    }
166
167
    // TODO: some of this probably wants to go elsewhere
168
    public function getMostRecentMembership() {
169
        $last_cons = '';
170
        $last_house = null;
171
        $last_party = null;
172
        if ( $this->current_member_anywhere() ) {
173
            $houses = array_keys(array_filter($this->current_member(), 'strlen'));
0 ignored issues
show
Unused Code introduced by
The assignment to $houses is dead and can be removed.
Loading history...
174
            $last_cons = $this->constituency;
175
            $last_party = $this->party;
176
            $last_house = $this->house_disp;
177
        } else {
178
            $max_date = null;
179
            foreach ( array_keys($this->left_house) as $house ) {
180
                if ($this->left_house[$house]['date'] > $max_date ) {
181
                    $max_date = $this->left_house[$house]['date'];
182
                    $last_cons = $this->left_house[$house]['constituency'];
183
                    $last_party = $this->left_house[$house]['party'];
184
                    $last_house = $house;
185
                }
186
            }
187
        }
188
        $details = array(
189
            'entered_house' => '',
190
            'left_house' => '',
191
            'cons' => $last_cons,
192
            'party' => $last_party,
193
            'house' => $last_house,
194
            'rep_name' => $this->getRepNameForHouse($last_house)
195
        );
196
197
        $entered_house = $this->entered_house($last_house);
198
        $left_house = $this->left_house($last_house);
199
        if ( isset($entered_house['date']) ) {
200
            $details['entered_house'] = $entered_house['date'];
201
        }
202
        if ( isset($left_house['date']) ) {
203
            $details['left_house'] = $left_house['date'];
204
        }
205
206
        return $details;
207
    }
208
209
    /**
210
    * Offices
211
    *
212
    * Return an array of Office objects held (or previously held) by the member.
213
    *
214
    * @param string $include_only  Restrict the list to include only "previous" or "current" offices.
215
    * @param bool   $ignore_committees Ignore offices that appear to be committee memberships.
216
    *
217
    * @return array An array of Office objects.
218
    */
219
220
    public function offices($include_only = NULL, $ignore_committees = FALSE) {
221
222
        $out = array();
223
224
        if (array_key_exists('office', $this->extra_info())) {
225
            $office = $this->extra_info();
226
            $office = $office['office'];
227
228
            foreach ($office as $row) {
229
                if ( $officeObject = $this->getOfficeObject($include_only, $ignore_committees, $row) ) {
230
                    $out[] = $officeObject;
231
                }
232
            }
233
        }
234
235
        return $out;
236
237
    }
238
239
    private function getOfficeObject($include_only, $ignore_committees, $row) {
240
        if (!$this->includeOffice($include_only, $row['to_date'])) {
241
            return null;
242
        }
243
        if ($ignore_committees && strpos($row['moffice_id'], 'Committee')) {
244
            return null;
245
        }
246
247
        $officeObject = new Office;
248
        $officeObject->title = prettify_office($row['position'], $row['dept']);
249
        $officeObject->from_date = $row['from_date'];
250
        $officeObject->to_date = $row['to_date'];
251
        $officeObject->source = $row['source'];
252
        return $officeObject;
253
    }
254
255
    private function includeOffice($include_only, $to_date) {
256
        $include_office = TRUE;
257
258
        // If we should only include previous offices, and the to date is in the future, suppress this office.
259
        if ($include_only == 'previous' AND $to_date == '9999-12-31') {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
260
            $include_office = FALSE;
261
        }
262
263
        // If we should only include previous offices, and the to date is in the past, suppress this office.
264
        if ($include_only == 'current' AND $to_date != '9999-12-31') {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
265
            $include_office = FALSE;
266
        }
267
268
        return $include_office;
269
    }
270
271
    /**
272
    * Get Other Parties String
273
    *
274
    * Return a readable list of party changes for this member.
275
    *
276
    * @return string|null A readable list of the party changes for this member.
277
    */
278
279
    public function getOtherPartiesString() {
280
281
        if (!empty($this->other_parties) && $this->party != 'Speaker' && $this->party != 'Deputy Speaker') {
282
            $output = 'Party was ';
283
            $other_parties = array();
284
            foreach ($this->other_parties as $r) {
285
                $other_parties[] = $r['from'] . ' until ' . format_date($r['date'], SHORTDATEFORMAT);
286
            }
287
            $output .= join('; ', $other_parties);
288
            return $output;
289
        } else {
290
            return NULL;
291
        }
292
293
    }
294
295
    public function getShortParty() {
296
        $party = $this->party();
297
        if ($party == 'Labour/Co-operative') {
298
            $party = 'Labour';
299
        }
300
        $party = str_replace(' ', '', $party);
301
        return $party;
302
    }
303
304
    /**
305
    * Get Other Constituencies String
306
    *
307
    * Return a readable list of other constituencies for this member.
308
    *
309
    * @return string|null A readable list of the other constituencies for this member.
310
    */
311
312
    public function getOtherConstituenciesString() {
313
314
        if ($this->other_constituencies) {
315
            return 'Also represented ' . join('; ', array_keys($this->other_constituencies));
316
        } else {
317
            return NULL;
318
        }
319
320
    }
321
322
    /**
323
    * Get Entered/Left Strings
324
    *
325
    * Return an array of readable strings covering when people entered or left
326
    * various houses. Returns an array since it's possible for a member to have
327
    * done several of these things.
328
    *
329
    * @return array An array of strings of when this member entered or left houses.
330
    */
331 1
    public function getEnterLeaveStrings() {
332 1
        $output = array();
333
334 1
        $output[] = $this->entered_house_line(HOUSE_TYPE_LORDS, 'House of Lords');
335
336 1
        if (isset($this->left_house[HOUSE_TYPE_COMMONS]) && isset($this->entered_house[HOUSE_TYPE_LORDS])) {
337
            $string = '<strong>Previously MP for ';
338
            $string .= $this->left_house[HOUSE_TYPE_COMMONS]['constituency'] . ' until ';
339
            $string .= $this->left_house[HOUSE_TYPE_COMMONS]['date_pretty'] . '</strong>';
340
            if ($this->left_house[HOUSE_TYPE_COMMONS]['reason']) {
341
                $string .= ' &mdash; ' . $this->left_house[HOUSE_TYPE_COMMONS]['reason'];
342
            }
343
            $output[] = $string;
344
        }
345
346 1
        $output[] = $this->left_house_line(HOUSE_TYPE_LORDS, 'House of Lords');
347
348 1
        if (isset($this->extra_info['lordbio'])) {
349
            $output[] = '<strong>Positions held at time of appointment:</strong> ' . $this->extra_info['lordbio'] .
350
                ' <small>(from <a href="' .
351
                $this->extra_info['lordbio_from'] . '">Number 10 press release</a>)</small>';
352
        }
353
354 1
        $output[] = $this->entered_house_line(HOUSE_TYPE_COMMONS, 'House of Commons');
355
356
        # If they became a Lord, we handled this above.
357 1
        if ($this->house(HOUSE_TYPE_COMMONS) && !$this->current_member(HOUSE_TYPE_COMMONS) && !$this->house(HOUSE_TYPE_LORDS)) {
358
            $output[] = $this->left_house_line(HOUSE_TYPE_COMMONS, 'House of Commons');
359
        }
360
361 1
        $output[] = $this->entered_house_line(HOUSE_TYPE_NI, 'Assembly');
362 1
        $output[] = $this->left_house_line(HOUSE_TYPE_NI, 'Assembly');
363 1
        $output[] = $this->entered_house_line(HOUSE_TYPE_SCOTLAND, 'Scottish Parliament');
364 1
        $output[] = $this->left_house_line(HOUSE_TYPE_SCOTLAND, 'Scottish Parliament');
365
366 1
        $output = array_values(array_filter($output));
367 1
        return $output;
368
    }
369
370 1
    private function entered_house_line($house, $house_name) {
371 1
        if (isset($this->entered_house[$house]['date'])) {
372 1
            $string = "<strong>Entered the $house_name ";
373 1
            $string .= strlen($this->entered_house[$house]['date_pretty'])==HOUSE_TYPE_SCOTLAND ? 'in ' : 'on ';
374 1
            $string .= $this->entered_house[$house]['date_pretty'] . '</strong>';
375 1
            if ($this->entered_house[$house]['reason']) {
376 1
                $string .= ' &mdash; ' . $this->entered_house[$house]['reason'];
377 1
            }
378 1
            return $string;
379
        }
380 1
    }
381
382 1
    private function left_house_line($house, $house_name) {
383 1
        if ($this->house($house) && !$this->current_member($house)) {
384 1
            $string = "<strong>Left the $house_name ";
385 1
            $string .= strlen($this->left_house[$house]['date_pretty'])==4 ? 'in ' : 'on ';
386 1
            $string .= $this->left_house[$house]['date_pretty'] . '</strong>';
387 1
            if ($this->left_house[$house]['reason']) {
388 1
                $string .= ' &mdash; ' . $this->left_house[$house]['reason'];
389 1
            }
390 1
            return $string;
391
        }
392 1
    }
393
394
    public function getPartyPolicyDiffs($party, $policiesList, $positions, $only_diffs = false) {
395
        $policy_diffs = array();
396
        $party_positions = $party->getAllPolicyPositions($policiesList);
397
398
        if ( !$party_positions ) {
399
            return $policy_diffs;
400
        }
401
402
        foreach ( $positions->positionsById as $policy_id => $details ) {
403
            if ( $details['has_strong'] && $details['score'] != -1 && isset($party_positions[$policy_id])) {
404
                $mp_score = $details['score'];
405
                $party_score = $party_positions[$policy_id]['score'];
406
407
                $score_diff = $this->calculatePolicyDiffScore($mp_score, $party_score);
408
409
                // skip anything that isn't a yes vs no diff
410
                if ( $only_diffs && $score_diff < 2 ) {
411
                    continue;
412
                }
413
                $policy_diffs[$policy_id] = $score_diff;
414
            }
415
        }
416
417
        arsort($policy_diffs);
418
419
        return $policy_diffs;
420
    }
421
422
    private function calculatePolicyDiffScore( $mp_score, $party_score ) {
423
        $score_diff = abs($mp_score - $party_score);
424
        // if they are on opposite sides of mixture of for and against
425
        if (
426
            ( $mp_score < 0.4 && $party_score > 0.6 ) ||
427
            ( $mp_score > 0.6 && $party_score < 0.4 )
428
        ) {
429
            $score_diff += 2;
430
        // if on is mixture of for and against and one is for/against
431
        } else if (
432
            ( $mp_score > 0.4 && $mp_score < 0.6 && ( $party_score > 0.6 || $party_score < 0.4 ) ) ||
0 ignored issues
show
introduced by
Consider adding parentheses for clarity. Current Interpretation: ($mp_score > 0.4 && $mp_... 0.6 || $mp_score < 0.4, Probably Intended Meaning: $mp_score > 0.4 && $mp_s...0.6 || $mp_score < 0.4)
Loading history...
433
            ( $party_score > 0.4 && $party_score < 0.6 && ( $mp_score > 0.6 || $mp_score < 0.4 ) )
434
        ) {
435
            $score_diff += 1;
436
        }
437
438
        return $score_diff;
439
    }
440
441 1
    public static function getRegionalList($postcode, $house, $type) {
442 1
        $db = new \ParlDB;
443
444 1
        $mreg = array();
445 1
        $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode);
446 1
        if ( isset($constituencies[$type]) ) {
447 1
            $cons_name = $constituencies[$type];
448
            $query_base = "SELECT member.person_id, title, lordofname, given_name, family_name, constituency, house
449
                FROM member, person_names
450
                WHERE
451
                member.person_id = person_names.person_id
452
                AND person_names.type = 'name'
453
                AND constituency = :cons_name
454
                AND house = :house
455
                AND left_house >= start_date
456 1
                AND left_house <= end_date";
457 1
            $q = $db->query("$query_base AND left_reason = 'still_in_office'",
458
                array(
459 1
                    ':house' => $house,
460
                    ':cons_name' => $cons_name
461 1
                )
462 1
            );
463 1
            if ( !$q->rows() && ($dissolution = Dissolution::db()) ) {
464
                $q = $db->query("$query_base AND $dissolution[query]",
465
                    array(
466
                        ':house' => $house,
467
                        ':cons_name' => $cons_name,
468
                    ) + $dissolution['params']
469
                );
470
            }
471
472 1
            for ($i = 0; $i < $q->rows; $i++) {
473 1
                $name = member_full_name($house, $q->field($i, 'title'),
474 1
                    $q->field($i, 'given_name'), $q->field($i, 'family_name'),
475 1
                    $q->field($i, 'lordofname'));
476
477 1
                $mreg[] = array(
478 1
                    'person_id' 	=> $q->field($i, 'person_id'),
479 1
                    'name' => $name,
480 1
                    'house' => $q->field($i, 'house'),
481 1
                    'constituency' 	=> $q->field($i, 'constituency')
482 1
                );
483 1
            }
484 1
        }
485
486 1
        return $mreg;
487
    }
488
489
    public static function getRepNameForHouse($house) {
490
        switch ( $house ) {
491
        case HOUSE_TYPE_COMMONS:
492
            $name = 'MP';
493
            break;
494
        case HOUSE_TYPE_LORDS:
495
            $name = 'Peer';
496
            break;
497
        case HOUSE_TYPE_NI:
498
            $name = 'MLA';
499
            break;
500
        case HOUSE_TYPE_SCOTLAND:
501
            $name = 'MSP';
502
            break;
503
        default:
504
            $name = '';
505
        }
506
        return $name;
507
    }
508
509
}
510