@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | public function getSetDescriptions() { |
| 312 | - return $this->set_descs; |
|
| 312 | + return $this->set_descs; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
@@ -397,18 +397,18 @@ discard block |
||
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | public function limitToArray($policies) { |
| 400 | - $out = array(); |
|
| 401 | - // Reassemble the new policies list based on the set. |
|
| 402 | - foreach ($policies as $policy) { |
|
| 403 | - if (isset($this->policies[$policy])) { |
|
| 404 | - $out[$policy] = $this->policies[$policy]; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - $new_policies = new self(); |
|
| 409 | - $new_policies->policies = $out; |
|
| 410 | - |
|
| 411 | - return $new_policies; |
|
| 400 | + $out = array(); |
|
| 401 | + // Reassemble the new policies list based on the set. |
|
| 402 | + foreach ($policies as $policy) { |
|
| 403 | + if (isset($this->policies[$policy])) { |
|
| 404 | + $out[$policy] = $this->policies[$policy]; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + $new_policies = new self(); |
|
| 409 | + $new_policies->policies = $out; |
|
| 410 | + |
|
| 411 | + return $new_policies; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | public function getPolicyDetails($policyID) { |
@@ -293,7 +293,7 @@ |
||
| 293 | 293 | |
| 294 | 294 | private $policy_id; |
| 295 | 295 | |
| 296 | - public function __construct($policy_id = NULL) { |
|
| 296 | + public function __construct($policy_id = null) { |
|
| 297 | 297 | $this->db = new \ParlDB; |
| 298 | 298 | |
| 299 | 299 | if ( $policy_id ) { |
@@ -366,14 +366,12 @@ |
||
| 366 | 366 | public function limitToSet($set) { |
| 367 | 367 | |
| 368 | 368 | // Sanity check the set exists |
| 369 | - if (isset($this->sets[$set])) |
|
| 370 | - { |
|
| 369 | + if (isset($this->sets[$set])) { |
|
| 371 | 370 | $out = array(); |
| 372 | 371 | // Reassemble the new policies list based on the set. |
| 373 | 372 | foreach ($this->sets[$set] as $set_policy) |
| 374 | 373 | { |
| 375 | - if (isset($this->policies[$set_policy])) |
|
| 376 | - { |
|
| 374 | + if (isset($this->policies[$set_policy])) { |
|
| 377 | 375 | $out[$set_policy] = $this->policies[$set_policy]; |
| 378 | 376 | } else { |
| 379 | 377 | // if we've limited the policies to a single one then we only |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | public function __construct($policy_id = NULL) { |
| 303 | 303 | $this->db = new \ParlDB; |
| 304 | 304 | |
| 305 | - if ( $policy_id ) { |
|
| 305 | + if ($policy_id) { |
|
| 306 | 306 | $this->policy_id = $policy_id; |
| 307 | 307 | $this->policies = array( |
| 308 | 308 | $policy_id => $this->policies[$policy_id] |
@@ -386,8 +386,8 @@ discard block |
||
| 386 | 386 | // want to complain here if we're looking for that policy and |
| 387 | 387 | // it does not exist. Otherwise, if the single policy isn't in |
| 388 | 388 | // the set we want to return an empty set |
| 389 | - if ( !isset($this->policy_id) || $set_policy == $this->policy_id ) { |
|
| 390 | - throw new \Exception ('Policy ' . $set_policy . ' in set "' . $set . '" does not exist.'); |
|
| 389 | + if (!isset($this->policy_id) || $set_policy == $this->policy_id) { |
|
| 390 | + throw new \Exception('Policy ' . $set_policy . ' in set "' . $set . '" does not exist.'); |
|
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | } |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | return $new_policies; |
| 399 | 399 | |
| 400 | 400 | } else { |
| 401 | - throw new \Exception ('Policy set "' . $set . '" does not exist.'); |
|
| 401 | + throw new \Exception('Policy set "' . $set . '" does not exist.'); |
|
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | |
| 440 | 440 | $image = $q['image']; |
| 441 | 441 | |
| 442 | - if ( $image && file_exists(BASEDIR . '/' . $image)) { |
|
| 442 | + if ($image && file_exists(BASEDIR . '/' . $image)) { |
|
| 443 | 443 | $props['image'] = $image; |
| 444 | 444 | $props['image_license'] = $q['image_license']; |
| 445 | 445 | $props['image_attribution'] = $q['image_attrib']; |
@@ -133,12 +133,12 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 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 | - */ |
|
| 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 | 142 | |
| 143 | 143 | public function image() { |
| 144 | 144 | |
@@ -207,15 +207,15 @@ discard block |
||
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 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 | - */ |
|
| 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 | 219 | |
| 220 | 220 | public function offices($include_only = NULL, $ignore_committees = FALSE) { |
| 221 | 221 | |
@@ -269,12 +269,12 @@ discard block |
||
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 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 | - */ |
|
| 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 | 278 | |
| 279 | 279 | public function getOtherPartiesString() { |
| 280 | 280 | |
@@ -302,12 +302,12 @@ discard block |
||
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 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 | - */ |
|
| 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 | 311 | |
| 312 | 312 | public function getOtherConstituenciesString() { |
| 313 | 313 | |
@@ -320,14 +320,14 @@ discard block |
||
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 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 | - */ |
|
| 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 | 331 | public function getEnterLeaveStrings() { |
| 332 | 332 | $output = array(); |
| 333 | 333 | |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | foreach ($house_types as $house_type) { |
| 41 | 41 | |
| 42 | - if (in_array($house_type, $left_house) AND |
|
| 43 | - $left_house[$house_type]['reason'] AND |
|
| 42 | + if (in_array($house_type, $left_house) and |
|
| 43 | + $left_house[$house_type]['reason'] and |
|
| 44 | 44 | $left_house[$house_type]['reason'] == 'Died' |
| 45 | 45 | ) { |
| 46 | 46 | |
| 47 | 47 | // This member has left a house because of death. |
| 48 | - return TRUE; |
|
| 48 | + return true; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | // If we get this far the member hasn't left a house due to death, and |
| 56 | 56 | // is presumably alive. |
| 57 | - return FALSE; |
|
| 57 | + return false; |
|
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | $diff = $date_entered->diff($now); |
| 78 | 78 | if ( $diff->y == 0 && $diff->m <= 6 ) { |
| 79 | - return TRUE; |
|
| 79 | + return true; |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - return FALSE; |
|
| 83 | + return false; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /* |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | return $this->extra_info()['eu_ref_stance']; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - return FALSE; |
|
| 132 | + return false; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -150,10 +150,10 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // We can determine if the image exists or not by testing if size is set |
| 153 | - if ($size !== NULL) { |
|
| 154 | - $exists = TRUE; |
|
| 153 | + if ($size !== null) { |
|
| 154 | + $exists = true; |
|
| 155 | 155 | } else { |
| 156 | - $exists = FALSE; |
|
| 156 | + $exists = false; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | return array( |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @return array An array of Office objects. |
| 218 | 218 | */ |
| 219 | 219 | |
| 220 | - public function offices($include_only = NULL, $ignore_committees = FALSE) { |
|
| 220 | + public function offices($include_only = null, $ignore_committees = false) { |
|
| 221 | 221 | |
| 222 | 222 | $out = array(); |
| 223 | 223 | |
@@ -253,16 +253,16 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | private function includeOffice($include_only, $to_date) { |
| 256 | - $include_office = TRUE; |
|
| 256 | + $include_office = true; |
|
| 257 | 257 | |
| 258 | 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') { |
|
| 260 | - $include_office = FALSE; |
|
| 259 | + if ($include_only == 'previous' and $to_date == '9999-12-31') { |
|
| 260 | + $include_office = false; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 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') { |
|
| 265 | - $include_office = FALSE; |
|
| 264 | + if ($include_only == 'current' and $to_date != '9999-12-31') { |
|
| 265 | + $include_office = false; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | return $include_office; |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | $output .= join('; ', $other_parties); |
| 288 | 288 | return $output; |
| 289 | 289 | } else { |
| 290 | - return NULL; |
|
| 290 | + return null; |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | if ($this->other_constituencies) { |
| 315 | 315 | return 'Also represented ' . join('; ', array_keys($this->other_constituencies)); |
| 316 | 316 | } else { |
| 317 | - return NULL; |
|
| 317 | + return null; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | } |
@@ -471,23 +471,23 @@ |
||
| 471 | 471 | |
| 472 | 472 | public static function getRepNameForHouse($house) { |
| 473 | 473 | switch ( $house ) { |
| 474 | - case HOUSE_TYPE_COMMONS: |
|
| 475 | - $name = 'MP'; |
|
| 476 | - break; |
|
| 477 | - case HOUSE_TYPE_LORDS: |
|
| 478 | - $name = 'Peer'; |
|
| 479 | - break; |
|
| 480 | - case HOUSE_TYPE_NI: |
|
| 481 | - $name = 'MLA'; |
|
| 482 | - break; |
|
| 483 | - case HOUSE_TYPE_SCOTLAND: |
|
| 484 | - $name = 'MSP'; |
|
| 485 | - break; |
|
| 486 | - case HOUSE_TYPE_ROYAL: |
|
| 487 | - $name = 'Member of royalty'; |
|
| 488 | - break; |
|
| 489 | - default: |
|
| 490 | - $name = ''; |
|
| 474 | + case HOUSE_TYPE_COMMONS: |
|
| 475 | + $name = 'MP'; |
|
| 476 | + break; |
|
| 477 | + case HOUSE_TYPE_LORDS: |
|
| 478 | + $name = 'Peer'; |
|
| 479 | + break; |
|
| 480 | + case HOUSE_TYPE_NI: |
|
| 481 | + $name = 'MLA'; |
|
| 482 | + break; |
|
| 483 | + case HOUSE_TYPE_SCOTLAND: |
|
| 484 | + $name = 'MSP'; |
|
| 485 | + break; |
|
| 486 | + case HOUSE_TYPE_ROYAL: |
|
| 487 | + $name = 'Member of royalty'; |
|
| 488 | + break; |
|
| 489 | + default: |
|
| 490 | + $name = ''; |
|
| 491 | 491 | } |
| 492 | 492 | return $name; |
| 493 | 493 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $now = new \DateTime(); |
| 76 | 76 | |
| 77 | 77 | $diff = $date_entered->diff($now); |
| 78 | - if ( $diff->y == 0 && $diff->m <= 6 ) { |
|
| 78 | + if ($diff->y == 0 && $diff->m <= 6) { |
|
| 79 | 79 | return TRUE; |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | $entered_house = $this->entered_house($house); |
| 98 | 98 | |
| 99 | - if ( $entered_house ) { |
|
| 99 | + if ($entered_house) { |
|
| 100 | 100 | $date_entered = $entered_house['date']; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | $left_house = $this->left_house($house); |
| 118 | 118 | |
| 119 | - if ( $left_house ) { |
|
| 119 | + if ($left_house) { |
|
| 120 | 120 | $date_left = $left_house['date']; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | $is_lord = $this->house(HOUSE_TYPE_LORDS); |
| 146 | 146 | if ($is_lord) { |
| 147 | - list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); |
|
| 147 | + list($image, $size) = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); |
|
| 148 | 148 | } else { |
| 149 | - list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, true); |
|
| 149 | + list($image, $size) = Utility\Member::findMemberImage($this->person_id(), false, true); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // We can determine if the image exists or not by testing if size is set |
@@ -169,10 +169,10 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | usort( |
| 171 | 171 | $departures, |
| 172 | - function ($a, $b) { |
|
| 173 | - if ( $a['date'] == $b['date'] ) { |
|
| 172 | + function($a, $b) { |
|
| 173 | + if ($a['date'] == $b['date']) { |
|
| 174 | 174 | return 0; |
| 175 | - } else if ( $a['date'] < $b['date'] ) { |
|
| 175 | + } else if ($a['date'] < $b['date']) { |
|
| 176 | 176 | return -1; |
| 177 | 177 | } else { |
| 178 | 178 | return 1; |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | $office = $office['office']; |
| 210 | 210 | |
| 211 | 211 | foreach ($office as $row) { |
| 212 | - if ( $officeObject = $this->getOfficeObject($include_only, $ignore_committees, $row) ) { |
|
| 212 | + if ($officeObject = $this->getOfficeObject($include_only, $ignore_committees, $row)) { |
|
| 213 | 213 | $out[] = $officeObject; |
| 214 | 214 | } |
| 215 | 215 | } |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | private function entered_house_line($house, $house_name) { |
| 354 | 354 | if (isset($this->entered_house[$house]['date'])) { |
| 355 | 355 | $string = "<strong>Entered the $house_name "; |
| 356 | - $string .= strlen($this->entered_house[$house]['date_pretty'])==HOUSE_TYPE_SCOTLAND ? 'in ' : 'on '; |
|
| 356 | + $string .= strlen($this->entered_house[$house]['date_pretty']) == HOUSE_TYPE_SCOTLAND ? 'in ' : 'on '; |
|
| 357 | 357 | $string .= $this->entered_house[$house]['date_pretty'] . '</strong>'; |
| 358 | 358 | if ($this->entered_house[$house]['reason']) { |
| 359 | 359 | $string .= ' — ' . $this->entered_house[$house]['reason']; |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | private function left_house_line($house, $house_name) { |
| 366 | 366 | if ($this->house($house) && !$this->current_member($house)) { |
| 367 | 367 | $string = "<strong>Left the $house_name "; |
| 368 | - $string .= strlen($this->left_house[$house]['date_pretty'])==4 ? 'in ' : 'on '; |
|
| 368 | + $string .= strlen($this->left_house[$house]['date_pretty']) == 4 ? 'in ' : 'on '; |
|
| 369 | 369 | $string .= $this->left_house[$house]['date_pretty'] . '</strong>'; |
| 370 | 370 | if ($this->left_house[$house]['reason']) { |
| 371 | 371 | $string .= ' — ' . $this->left_house[$house]['reason']; |
@@ -378,19 +378,19 @@ discard block |
||
| 378 | 378 | $policy_diffs = array(); |
| 379 | 379 | $party_positions = $party->getAllPolicyPositions($policiesList); |
| 380 | 380 | |
| 381 | - if ( !$party_positions ) { |
|
| 381 | + if (!$party_positions) { |
|
| 382 | 382 | return $policy_diffs; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - foreach ( $positions->positionsById as $policy_id => $details ) { |
|
| 386 | - if ( $details['has_strong'] && $details['score'] != -1 && isset($party_positions[$policy_id])) { |
|
| 385 | + foreach ($positions->positionsById as $policy_id => $details) { |
|
| 386 | + if ($details['has_strong'] && $details['score'] != -1 && isset($party_positions[$policy_id])) { |
|
| 387 | 387 | $mp_score = $details['score']; |
| 388 | 388 | $party_score = $party_positions[$policy_id]['score']; |
| 389 | 389 | |
| 390 | 390 | $score_diff = $this->calculatePolicyDiffScore($mp_score, $party_score); |
| 391 | 391 | |
| 392 | 392 | // skip anything that isn't a yes vs no diff |
| 393 | - if ( $only_diffs && $score_diff < 2 ) { |
|
| 393 | + if ($only_diffs && $score_diff < 2) { |
|
| 394 | 394 | continue; |
| 395 | 395 | } |
| 396 | 396 | $policy_diffs[$policy_id] = $score_diff; |
@@ -402,18 +402,18 @@ discard block |
||
| 402 | 402 | return $policy_diffs; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - private function calculatePolicyDiffScore( $mp_score, $party_score ) { |
|
| 405 | + private function calculatePolicyDiffScore($mp_score, $party_score) { |
|
| 406 | 406 | $score_diff = abs($mp_score - $party_score); |
| 407 | 407 | // if they are on opposite sides of mixture of for and against |
| 408 | 408 | if ( |
| 409 | - ( $mp_score < 0.4 && $party_score > 0.6 ) || |
|
| 410 | - ( $mp_score > 0.6 && $party_score < 0.4 ) |
|
| 409 | + ($mp_score < 0.4 && $party_score > 0.6) || |
|
| 410 | + ($mp_score > 0.6 && $party_score < 0.4) |
|
| 411 | 411 | ) { |
| 412 | 412 | $score_diff += 2; |
| 413 | 413 | // if on is mixture of for and against and one is for/against |
| 414 | 414 | } else if ( |
| 415 | - ( $mp_score > 0.4 && $mp_score < 0.6 && ( $party_score > 0.6 || $party_score < 0.4 ) ) || |
|
| 416 | - ( $party_score > 0.4 && $party_score < 0.6 && ( $mp_score > 0.6 || $mp_score < 0.4 ) ) |
|
| 415 | + ($mp_score > 0.4 && $mp_score < 0.6 && ($party_score > 0.6 || $party_score < 0.4)) || |
|
| 416 | + ($party_score > 0.4 && $party_score < 0.6 && ($mp_score > 0.6 || $mp_score < 0.4)) |
|
| 417 | 417 | ) { |
| 418 | 418 | $score_diff += 1; |
| 419 | 419 | } |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | |
| 427 | 427 | $mreg = array(); |
| 428 | 428 | $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode); |
| 429 | - if ( isset($constituencies[$type]) ) { |
|
| 429 | + if (isset($constituencies[$type])) { |
|
| 430 | 430 | $cons_name = $constituencies[$type]; |
| 431 | 431 | $query_base = "SELECT member.person_id, title, lordofname, given_name, family_name, constituency, house |
| 432 | 432 | FROM member, person_names |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | ':cons_name' => $cons_name |
| 444 | 444 | ) |
| 445 | 445 | ); |
| 446 | - if ( !$q->rows() && ($dissolution = Dissolution::db()) ) { |
|
| 446 | + if (!$q->rows() && ($dissolution = Dissolution::db())) { |
|
| 447 | 447 | $q = $db->query("$query_base AND $dissolution[query]", |
| 448 | 448 | array( |
| 449 | 449 | ':house' => $house, |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | public static function getRepNameForHouse($house) { |
| 473 | - switch ( $house ) { |
|
| 473 | + switch ($house) { |
|
| 474 | 474 | case HOUSE_TYPE_COMMONS: |
| 475 | 475 | $name = 'MP'; |
| 476 | 476 | break; |
@@ -82,42 +82,42 @@ |
||
| 82 | 82 | private function prettify_search_section($section) { |
| 83 | 83 | $name = ''; |
| 84 | 84 | switch ($section) { |
| 85 | - case 'wrans': |
|
| 86 | - $name = 'Written Answers'; |
|
| 87 | - break; |
|
| 88 | - case 'uk': |
|
| 89 | - $name = 'All UK'; |
|
| 90 | - break; |
|
| 91 | - case 'debates': |
|
| 92 | - $name = 'House of Commons debates'; |
|
| 93 | - break; |
|
| 94 | - case 'whall': |
|
| 95 | - $name = 'Westminster Hall debates'; |
|
| 96 | - break; |
|
| 97 | - case 'lords': |
|
| 98 | - $name = 'House of Lords debates'; |
|
| 99 | - break; |
|
| 100 | - case 'wms': |
|
| 101 | - $name = 'Written ministerial statements'; |
|
| 102 | - break; |
|
| 103 | - case 'standing': |
|
| 104 | - $name = 'Bill Committees'; |
|
| 105 | - break; |
|
| 106 | - case 'future': |
|
| 107 | - $name = 'Future Business'; |
|
| 108 | - break; |
|
| 109 | - case 'ni': |
|
| 110 | - $name = 'Northern Ireland Assembly Debates'; |
|
| 111 | - break; |
|
| 112 | - case 'scotland': |
|
| 113 | - $name = 'All Scotland'; |
|
| 114 | - break; |
|
| 115 | - case 'sp': |
|
| 116 | - $name = 'Scottish Parliament Debates'; |
|
| 117 | - break; |
|
| 118 | - case 'spwrans': |
|
| 119 | - $name = 'Scottish Parliament Written answers'; |
|
| 120 | - break; |
|
| 85 | + case 'wrans': |
|
| 86 | + $name = 'Written Answers'; |
|
| 87 | + break; |
|
| 88 | + case 'uk': |
|
| 89 | + $name = 'All UK'; |
|
| 90 | + break; |
|
| 91 | + case 'debates': |
|
| 92 | + $name = 'House of Commons debates'; |
|
| 93 | + break; |
|
| 94 | + case 'whall': |
|
| 95 | + $name = 'Westminster Hall debates'; |
|
| 96 | + break; |
|
| 97 | + case 'lords': |
|
| 98 | + $name = 'House of Lords debates'; |
|
| 99 | + break; |
|
| 100 | + case 'wms': |
|
| 101 | + $name = 'Written ministerial statements'; |
|
| 102 | + break; |
|
| 103 | + case 'standing': |
|
| 104 | + $name = 'Bill Committees'; |
|
| 105 | + break; |
|
| 106 | + case 'future': |
|
| 107 | + $name = 'Future Business'; |
|
| 108 | + break; |
|
| 109 | + case 'ni': |
|
| 110 | + $name = 'Northern Ireland Assembly Debates'; |
|
| 111 | + break; |
|
| 112 | + case 'scotland': |
|
| 113 | + $name = 'All Scotland'; |
|
| 114 | + break; |
|
| 115 | + case 'sp': |
|
| 116 | + $name = 'Scottish Parliament Debates'; |
|
| 117 | + break; |
|
| 118 | + case 'spwrans': |
|
| 119 | + $name = 'Scottish Parliament Written answers'; |
|
| 120 | + break; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | return $name; |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $this->searchstring = $argparser->construct_search_string(); |
| 20 | 20 | $this->searchkeyword = $argparser->searchkeyword; |
| 21 | 21 | |
| 22 | - if ( !$this->searchstring ) { |
|
| 22 | + if (!$this->searchstring) { |
|
| 23 | 23 | $data = $this->get_form_params($data); |
| 24 | 24 | $data['searchstring'] = ''; |
| 25 | 25 | $data['template'] = 'search/results'; |
@@ -28,14 +28,14 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | $this->searchstring = filter_user_input($this->searchstring, 'strict'); |
| 30 | 30 | $warnings = $this->validate_search_string(); |
| 31 | - if ( $warnings ) { |
|
| 31 | + if ($warnings) { |
|
| 32 | 32 | $data['warnings'] = $warnings; |
| 33 | 33 | $data['template'] = 'search/results'; |
| 34 | 34 | $data['searchstring'] = $this->searchstring; |
| 35 | 35 | $data = $this->get_form_params($data); |
| 36 | 36 | return $data; |
| 37 | 37 | } else { |
| 38 | - if (get_http_var('o')=='p') { |
|
| 38 | + if (get_http_var('o') == 'p') { |
|
| 39 | 39 | $search = new Search\ByUsage(); |
| 40 | 40 | $data = $search->search($this->searchstring); |
| 41 | 41 | $data['template'] = 'search/by-person'; |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $data['person_name'] = $MEMBER->full_name(); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if ( isset($data['info']['spelling_correction']) ) { |
|
| 55 | + if (isset($data['info']['spelling_correction'])) { |
|
| 56 | 56 | $data['info']['spelling_correction_display'] = $this->prettifySearchString($data['info']['spelling_correction']); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -144,15 +144,15 @@ discard block |
||
| 144 | 144 | $data['search_keyword'] = $this->searchkeyword; |
| 145 | 145 | |
| 146 | 146 | $is_adv = false; |
| 147 | - foreach ( array('to', 'from', 'person', 'section', 'column', 'phrase', 'exclude' ) as $var ) { |
|
| 147 | + foreach (array('to', 'from', 'person', 'section', 'column', 'phrase', 'exclude') as $var) { |
|
| 148 | 148 | $key = "search_$var"; |
| 149 | - $data[$key] = get_http_var( $var ); |
|
| 150 | - if ( $data[$key] ) { |
|
| 149 | + $data[$key] = get_http_var($var); |
|
| 150 | + if ($data[$key]) { |
|
| 151 | 151 | $is_adv = true; |
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - if ( isset($data['search_section']) ) { |
|
| 155 | + if (isset($data['search_section'])) { |
|
| 156 | 156 | $data['search_section_pretty'] = $this->prettify_search_section($data['search_section']); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -162,16 +162,16 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | private function set_wtt_options($data) { |
| 164 | 164 | $data['wtt'] = ''; |
| 165 | - if ( $wtt = get_http_var('wtt') ) { |
|
| 165 | + if ($wtt = get_http_var('wtt')) { |
|
| 166 | 166 | $data['wtt'] = $wtt; |
| 167 | - if ( $wtt == 2 && $pid = get_http_var('pid') ) { |
|
| 167 | + if ($wtt == 2 && $pid = get_http_var('pid')) { |
|
| 168 | 168 | $data['pid'] = null; |
| 169 | 169 | try { |
| 170 | 170 | $lord = new Member(array('person_id' => $pid, 'house' => 2)); |
| 171 | - } catch ( MemberException $e ) { |
|
| 171 | + } catch (MemberException $e) { |
|
| 172 | 172 | return $data; |
| 173 | 173 | } |
| 174 | - if ( $lord->valid ) { |
|
| 174 | + if ($lord->valid) { |
|
| 175 | 175 | $data['pid'] = $pid; |
| 176 | 176 | $data['wtt_lord_name'] = $lord->full_name(); |
| 177 | 177 | } |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | $url->insert(array('q' => $value)); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if ( $params ) { |
|
| 200 | - if ( get_http_var('house') ) { |
|
| 199 | + if ($params) { |
|
| 200 | + if (get_http_var('house')) { |
|
| 201 | 201 | $url->insert(array('house' => get_http_var('house'))); |
| 202 | 202 | } |
| 203 | - if ( get_http_var('wtt') ) { |
|
| 203 | + if (get_http_var('wtt')) { |
|
| 204 | 204 | $url->insert(array('wtt' => get_http_var('wtt'))); |
| 205 | 205 | } |
| 206 | 206 | } else { |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | global $DATA, $this_page; |
| 215 | 215 | |
| 216 | 216 | $pagetitle = ''; |
| 217 | - if ( isset($data['search_type']) && $data['search_type'] == 'person' ) { |
|
| 217 | + if (isset($data['search_type']) && $data['search_type'] == 'person') { |
|
| 218 | 218 | if (isset($data['wtt']) && $data['wtt'] > 0) { |
| 219 | 219 | $pagetitle = 'League table of Lords who say ' . $data['pagetitle']; |
| 220 | 220 | } else { |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | protected function getRegionalList() { |
| 51 | - return NULL; |
|
| 51 | + return null; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | protected function getEditorialContent() { |
@@ -57,14 +57,14 @@ discard block |
||
| 57 | 57 | $gid = $featured->get_gid(); |
| 58 | 58 | $gidCheck = new Gid($gid); |
| 59 | 59 | $gid = $gidCheck->checkForRedirect(); |
| 60 | - if ( $gid ) { |
|
| 60 | + if ($gid) { |
|
| 61 | 61 | $title = $featured->get_title(); |
| 62 | 62 | $context = $featured->get_context(); |
| 63 | 63 | $related = $featured->get_related(); |
| 64 | 64 | $item = $this->getFeaturedDebate($gid, $title, $context, $related); |
| 65 | 65 | } else { |
| 66 | 66 | $item = $debatelist->display('recent_debates', array('days' => 7, 'num' => 1), 'none'); |
| 67 | - if ( isset($item['data']) && count($item['data']) ) { |
|
| 67 | + if (isset($item['data']) && count($item['data'])) { |
|
| 68 | 68 | $item = $item['data'][0]; |
| 69 | 69 | $more_url = new Url('debates'); |
| 70 | 70 | $item['more_url'] = $more_url->generate(); |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | $item['featured'] = true; |
| 96 | 96 | |
| 97 | 97 | $related_debates = array(); |
| 98 | - foreach ( $related as $related_gid ) { |
|
| 99 | - if ( $related_gid ) { |
|
| 98 | + foreach ($related as $related_gid) { |
|
| 99 | + if ($related_gid) { |
|
| 100 | 100 | $related_item = $debatelist->display('featured_gid', array('gid' => $related_gid), 'none'); |
| 101 | 101 | $related_debates[] = $related_item['data']; |
| 102 | 102 | } |
@@ -121,21 +121,21 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | $recent_content = array(); |
| 123 | 123 | |
| 124 | - foreach ( $this->recent_types as $class => $recent ) { |
|
| 124 | + foreach ($this->recent_types as $class => $recent) { |
|
| 125 | 125 | $class = "\\$class"; |
| 126 | 126 | $instance = new $class(); |
| 127 | 127 | $more_url = new Url($recent[1]); |
| 128 | - if ( $recent[0] == 'recent_pbc_debates' ) { |
|
| 129 | - $content = array( 'data' => $instance->display($recent[0], array('num' => 5), 'none') ); |
|
| 128 | + if ($recent[0] == 'recent_pbc_debates') { |
|
| 129 | + $content = array('data' => $instance->display($recent[0], array('num' => 5), 'none')); |
|
| 130 | 130 | } else { |
| 131 | 131 | $content = $instance->display($recent[0], array('days' => 7, 'num' => 1), 'none'); |
| 132 | - if ( isset($content['data']) && count($content['data']) ) { |
|
| 132 | + if (isset($content['data']) && count($content['data'])) { |
|
| 133 | 133 | $content = $content['data'][0]; |
| 134 | 134 | } else { |
| 135 | 135 | $content = array(); |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | - if ( $content ) { |
|
| 138 | + if ($content) { |
|
| 139 | 139 | $content['more_url'] = $more_url->generate(); |
| 140 | 140 | $content['desc'] = $recent[2]; |
| 141 | 141 | $recent_content[] = $content; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | WHERE event_date >= :date |
| 155 | 155 | AND deleted = 0 |
| 156 | 156 | ORDER BY event_date, chamber, pos", |
| 157 | - array( ':date' => $date ) |
|
| 157 | + array(':date' => $date) |
|
| 158 | 158 | ); |
| 159 | 159 | |
| 160 | 160 | $data = array(); |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | class Hansard |
| 12 | 12 | { |
| 13 | 13 | public static function get_gid_from_url($url) { |
| 14 | - $gid = NULL; |
|
| 14 | + $gid = null; |
|
| 15 | 15 | $parts = parse_url($url); |
| 16 | 16 | parse_str($parts['query'], $query); |
| 17 | 17 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | $parts = parse_url($url); |
| 16 | 16 | parse_str($parts['query'], $query); |
| 17 | 17 | |
| 18 | - if ( $query['id'] ) { |
|
| 18 | + if ($query['id']) { |
|
| 19 | 19 | if (strpos($parts['path'], 'lords') !== false) { |
| 20 | 20 | $gid = 'uk.org.publicwhip/lords/'; |
| 21 | 21 | } elseif (strpos($parts['path'], 'whall') !== false) { |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | public static function gid_to_url($gid) { |
| 33 | - if ( !$gid ) { |
|
| 33 | + if (!$gid) { |
|
| 34 | 34 | return ''; |
| 35 | 35 | } |
| 36 | 36 | global $hansardmajors; |
| 37 | 37 | $db = new \ParlDB(); |
| 38 | 38 | |
| 39 | - $q = $db->query("SELECT major FROM hansard WHERE gid = :gid", array( ':gid' => $gid ))->first(); |
|
| 39 | + $q = $db->query("SELECT major FROM hansard WHERE gid = :gid", array(':gid' => $gid))->first(); |
|
| 40 | 40 | $url_gid = fix_gid_from_db($gid); |
| 41 | 41 | $url = new \MySociety\TheyWorkForYou\Url($hansardmajors[$q['major']]['page']); |
| 42 | 42 | $url->insert(array('id' => $url_gid)); |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | if (defined('OPTION_GAZE_URL') && OPTION_GAZE_URL) { |
| 26 | 26 | return gaze_get_country_from_ip($ip); |
| 27 | 27 | } else { |
| 28 | - return NULL; |
|
| 28 | + return null; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | } |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | |
| 40 | 40 | if ($last_postcode == $postcode) { |
| 41 | 41 | $return_value = $mp_only ? $last_postcode_value['WMC'] : $last_postcode_value; |
| 42 | - twfy_debug ("TIME", "Postcode $postcode looked up last time, is " . ( is_array($return_value) ? implode(', ', $return_value) : $return_value )); |
|
| 42 | + twfy_debug ("TIME", "postcode $postcode looked up last time, is " . ( is_array($return_value) ? implode(', ', $return_value) : $return_value )); |
|
| 43 | 43 | return $return_value; |
| 44 | 44 | } |
| 45 | 45 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | if ($last_postcode == $postcode) { |
| 41 | 41 | $return_value = $mp_only ? $last_postcode_value['WMC'] : $last_postcode_value; |
| 42 | - twfy_debug ("TIME", "Postcode $postcode looked up last time, is " . ( is_array($return_value) ? implode(', ', $return_value) : $return_value )); |
|
| 42 | + twfy_debug("TIME", "Postcode $postcode looked up last time, is " . (is_array($return_value) ? implode(', ', $return_value) : $return_value)); |
|
| 43 | 43 | return $return_value; |
| 44 | 44 | } |
| 45 | 45 | |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | $name = $q['name']; |
| 76 | 76 | if (self::postcodeIsScottish($postcode)) { |
| 77 | 77 | $name = explode('|', $name); |
| 78 | - if (count($name)==3) |
|
| 78 | + if (count($name) == 3) |
|
| 79 | 79 | return array('WMC' => $name[0], 'SPC' => $name[1], 'SPE' => $name[2]); |
| 80 | 80 | } elseif (self::postcodeIsNi($postcode)) { |
| 81 | 81 | $name = explode('|', $name); |
| 82 | - if (count($name)==2) |
|
| 82 | + if (count($name) == 2) |
|
| 83 | 83 | return array('WMC' => $name[0], 'NIE' => $name[1]); |
| 84 | 84 | } else { |
| 85 | 85 | return array('WMC' => $name); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | $r = json_decode($file, true); |
| 115 | 115 | if (!$r) { |
| 116 | - trigger_error("Postcode database is not working. Content:\n".$file.", request: ". $filename, E_USER_WARNING); |
|
| 116 | + trigger_error("Postcode database is not working. Content:\n" . $file . ", request: " . $filename, E_USER_WARNING); |
|
| 117 | 117 | return ''; |
| 118 | 118 | } |
| 119 | 119 | if (isset($r['error']) || !isset($r['areas'])) { |
@@ -179,29 +179,29 @@ discard block |
||
| 179 | 179 | if (in_array($m[1], array('AB', 'DD', 'EH', 'FK', 'G', 'HS', 'IV', 'KA', 'KW', 'KY', 'ML', 'PA', 'PH', 'ZE'))) |
| 180 | 180 | return true; |
| 181 | 181 | |
| 182 | - if ($m[1]=='DG') { |
|
| 183 | - if ($m[2]==16 && $m[3]==5 && in_array($m[4], array('HT','HU','HZ','JA','JB'))) return false; # A few postcodes in England |
|
| 182 | + if ($m[1] == 'DG') { |
|
| 183 | + if ($m[2] == 16 && $m[3] == 5 && in_array($m[4], array('HT', 'HU', 'HZ', 'JA', 'JB'))) return false; # A few postcodes in England |
|
| 184 | 184 | return true; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | # Damn postcodes crossing country boundaries |
| 188 | - if ($m[1]=='TD') { |
|
| 189 | - if ($m[2]!=15 && $m[2]!=12 && $m[2]!=9) return true; # TD1-8, 10-11, 13-14 all in Scotland |
|
| 190 | - if ($m[2]==9) { |
|
| 191 | - if ($m[3]!=0) return true; # TD9 1-9 all in Scotland |
|
| 192 | - if (!in_array($m[4], array('TJ','TP','TR','TS','TT','TU','TW'))) return true; # Nearly all of TD9 0 in Scotland |
|
| 188 | + if ($m[1] == 'TD') { |
|
| 189 | + if ($m[2] != 15 && $m[2] != 12 && $m[2] != 9) return true; # TD1-8, 10-11, 13-14 all in Scotland |
|
| 190 | + if ($m[2] == 9) { |
|
| 191 | + if ($m[3] != 0) return true; # TD9 1-9 all in Scotland |
|
| 192 | + if (!in_array($m[4], array('TJ', 'TP', 'TR', 'TS', 'TT', 'TU', 'TW'))) return true; # Nearly all of TD9 0 in Scotland |
|
| 193 | 193 | } |
| 194 | 194 | $m[5] = substr($m[4], 0, 1); |
| 195 | - if ($m[2]==12) { # $m[3] will be 4 currently. |
|
| 196 | - if ($m[4]=='XE') return true; |
|
| 197 | - if (in_array($m[5], array('A','B','D','E','H','J','L','N','W','Y'))) return true; # These bits of TD12 4 are in Scotland, others (Q, R, S, T, U, X) in England |
|
| 195 | + if ($m[2] == 12) { # $m[3] will be 4 currently. |
|
| 196 | + if ($m[4] == 'XE') return true; |
|
| 197 | + if (in_array($m[5], array('A', 'B', 'D', 'E', 'H', 'J', 'L', 'N', 'W', 'Y'))) return true; # These bits of TD12 4 are in Scotland, others (Q, R, S, T, U, X) in England |
|
| 198 | 198 | } |
| 199 | 199 | # TD15 is mostly England |
| 200 | - if ($m[2]==15) { |
|
| 201 | - if ($m[3]!=1) return false; # TD15 2 and 9 are in England |
|
| 202 | - if (in_array($m[4], array('BT','SU','SZ','UF','UG','UH','UJ','UL','US','UZ','WY','WZ'))) return true; |
|
| 203 | - if ($m[5]=='T' && $m[4]!='TA' && $m[4]!='TB') return true; # Most of TD15 1T* in Scotland |
|
| 204 | - if ($m[5]=='X' && $m[4]!='XX') return true; # TD15 1XX in England, rest of TD15 1X* in Scotland |
|
| 200 | + if ($m[2] == 15) { |
|
| 201 | + if ($m[3] != 1) return false; # TD15 2 and 9 are in England |
|
| 202 | + if (in_array($m[4], array('BT', 'SU', 'SZ', 'UF', 'UG', 'UH', 'UJ', 'UL', 'US', 'UZ', 'WY', 'WZ'))) return true; |
|
| 203 | + if ($m[5] == 'T' && $m[4] != 'TA' && $m[4] != 'TB') return true; # Most of TD15 1T* in Scotland |
|
| 204 | + if ($m[5] == 'X' && $m[4] != 'XX') return true; # TD15 1XX in England, rest of TD15 1X* in Scotland |
|
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
@@ -52,7 +52,9 @@ discard block |
||
| 52 | 52 | $ret = self::postcodeFetchFromMapit($postcode); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if (is_string($ret)) return $ret; |
|
| 55 | + if (is_string($ret)) { |
|
| 56 | + return $ret; |
|
| 57 | + } |
|
| 56 | 58 | |
| 57 | 59 | $last_postcode = $postcode; |
| 58 | 60 | $last_postcode_value = $ret; |
@@ -75,12 +77,14 @@ discard block |
||
| 75 | 77 | $name = $q['name']; |
| 76 | 78 | if (self::postcodeIsScottish($postcode)) { |
| 77 | 79 | $name = explode('|', $name); |
| 78 | - if (count($name)==3) |
|
| 79 | - return array('WMC' => $name[0], 'SPC' => $name[1], 'SPE' => $name[2]); |
|
| 80 | + if (count($name)==3) { |
|
| 81 | + return array('WMC' => $name[0], 'SPC' => $name[1], 'SPE' => $name[2]); |
|
| 82 | + } |
|
| 80 | 83 | } elseif (self::postcodeIsNi($postcode)) { |
| 81 | 84 | $name = explode('|', $name); |
| 82 | - if (count($name)==2) |
|
| 83 | - return array('WMC' => $name[0], 'NIE' => $name[1]); |
|
| 85 | + if (count($name)==2) { |
|
| 86 | + return array('WMC' => $name[0], 'NIE' => $name[1]); |
|
| 87 | + } |
|
| 84 | 88 | } else { |
| 85 | 89 | return array('WMC' => $name); |
| 86 | 90 | } |
@@ -121,8 +125,9 @@ discard block |
||
| 121 | 125 | } |
| 122 | 126 | $areas = array(); |
| 123 | 127 | foreach ($r['areas'] as $row) { |
| 124 | - if (in_array($row['type'], array('WMC', 'SPC', 'SPE', 'NIE'))) |
|
| 125 | - $areas[$row['type']] = $row['name']; |
|
| 128 | + if (in_array($row['type'], array('WMC', 'SPC', 'SPE', 'NIE'))) { |
|
| 129 | + $areas[$row['type']] = $row['name']; |
|
| 130 | + } |
|
| 126 | 131 | } |
| 127 | 132 | |
| 128 | 133 | if (!isset($areas['WMC'])) { |
@@ -172,36 +177,67 @@ discard block |
||
| 172 | 177 | */ |
| 173 | 178 | |
| 174 | 179 | public static function postcodeIsScottish($pc) { |
| 175 | - if (!preg_match('#^([A-Z]{1,2})(\d+) (\d)([A-Z]{2})#', self::canonicalisePostcode($pc), $m)) |
|
| 176 | - return false; |
|
| 180 | + if (!preg_match('#^([A-Z]{1,2})(\d+) (\d)([A-Z]{2})#', self::canonicalisePostcode($pc), $m)) { |
|
| 181 | + return false; |
|
| 182 | + } |
|
| 177 | 183 | |
| 178 | 184 | # Check for Scottish postal areas |
| 179 | - if (in_array($m[1], array('AB', 'DD', 'EH', 'FK', 'G', 'HS', 'IV', 'KA', 'KW', 'KY', 'ML', 'PA', 'PH', 'ZE'))) |
|
| 180 | - return true; |
|
| 185 | + if (in_array($m[1], array('AB', 'DD', 'EH', 'FK', 'G', 'HS', 'IV', 'KA', 'KW', 'KY', 'ML', 'PA', 'PH', 'ZE'))) { |
|
| 186 | + return true; |
|
| 187 | + } |
|
| 181 | 188 | |
| 182 | 189 | if ($m[1]=='DG') { |
| 183 | - if ($m[2]==16 && $m[3]==5 && in_array($m[4], array('HT','HU','HZ','JA','JB'))) return false; # A few postcodes in England |
|
| 190 | + if ($m[2]==16 && $m[3]==5 && in_array($m[4], array('HT','HU','HZ','JA','JB'))) { |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 193 | + # A few postcodes in England |
|
| 184 | 194 | return true; |
| 185 | 195 | } |
| 186 | 196 | |
| 187 | 197 | # Damn postcodes crossing country boundaries |
| 188 | 198 | if ($m[1]=='TD') { |
| 189 | - if ($m[2]!=15 && $m[2]!=12 && $m[2]!=9) return true; # TD1-8, 10-11, 13-14 all in Scotland |
|
| 199 | + if ($m[2]!=15 && $m[2]!=12 && $m[2]!=9) { |
|
| 200 | + return true; |
|
| 201 | + } |
|
| 202 | + # TD1-8, 10-11, 13-14 all in Scotland |
|
| 190 | 203 | if ($m[2]==9) { |
| 191 | - if ($m[3]!=0) return true; # TD9 1-9 all in Scotland |
|
| 192 | - if (!in_array($m[4], array('TJ','TP','TR','TS','TT','TU','TW'))) return true; # Nearly all of TD9 0 in Scotland |
|
| 204 | + if ($m[3]!=0) { |
|
| 205 | + return true; |
|
| 206 | + } |
|
| 207 | + # TD9 1-9 all in Scotland |
|
| 208 | + if (!in_array($m[4], array('TJ','TP','TR','TS','TT','TU','TW'))) { |
|
| 209 | + return true; |
|
| 210 | + } |
|
| 211 | + # Nearly all of TD9 0 in Scotland |
|
| 193 | 212 | } |
| 194 | 213 | $m[5] = substr($m[4], 0, 1); |
| 195 | - if ($m[2]==12) { # $m[3] will be 4 currently. |
|
| 196 | - if ($m[4]=='XE') return true; |
|
| 197 | - if (in_array($m[5], array('A','B','D','E','H','J','L','N','W','Y'))) return true; # These bits of TD12 4 are in Scotland, others (Q, R, S, T, U, X) in England |
|
| 214 | + if ($m[2]==12) { |
|
| 215 | +# $m[3] will be 4 currently. |
|
| 216 | + if ($m[4]=='XE') { |
|
| 217 | + return true; |
|
| 218 | + } |
|
| 219 | + if (in_array($m[5], array('A','B','D','E','H','J','L','N','W','Y'))) { |
|
| 220 | + return true; |
|
| 221 | + } |
|
| 222 | + # These bits of TD12 4 are in Scotland, others (Q, R, S, T, U, X) in England |
|
| 198 | 223 | } |
| 199 | 224 | # TD15 is mostly England |
| 200 | 225 | if ($m[2]==15) { |
| 201 | - if ($m[3]!=1) return false; # TD15 2 and 9 are in England |
|
| 202 | - if (in_array($m[4], array('BT','SU','SZ','UF','UG','UH','UJ','UL','US','UZ','WY','WZ'))) return true; |
|
| 203 | - if ($m[5]=='T' && $m[4]!='TA' && $m[4]!='TB') return true; # Most of TD15 1T* in Scotland |
|
| 204 | - if ($m[5]=='X' && $m[4]!='XX') return true; # TD15 1XX in England, rest of TD15 1X* in Scotland |
|
| 226 | + if ($m[3]!=1) { |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + # TD15 2 and 9 are in England |
|
| 230 | + if (in_array($m[4], array('BT','SU','SZ','UF','UG','UH','UJ','UL','US','UZ','WY','WZ'))) { |
|
| 231 | + return true; |
|
| 232 | + } |
|
| 233 | + if ($m[5]=='T' && $m[4]!='TA' && $m[4]!='TB') { |
|
| 234 | + return true; |
|
| 235 | + } |
|
| 236 | + # Most of TD15 1T* in Scotland |
|
| 237 | + if ($m[5]=='X' && $m[4]!='XX') { |
|
| 238 | + return true; |
|
| 239 | + } |
|
| 240 | + # TD15 1XX in England, rest of TD15 1X* in Scotland |
|
| 205 | 241 | } |
| 206 | 242 | } |
| 207 | 243 | |
@@ -215,8 +251,9 @@ discard block |
||
| 215 | 251 | |
| 216 | 252 | public static function postcodeIsNi($pc) { |
| 217 | 253 | $prefix = substr(self::canonicalisePostcode($pc), 0, 2); |
| 218 | - if ($prefix == 'BT') |
|
| 219 | - return true; |
|
| 254 | + if ($prefix == 'BT') { |
|
| 255 | + return true; |
|
| 256 | + } |
|
| 220 | 257 | return false; |
| 221 | 258 | } |
| 222 | 259 | |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | protected function getCalendarData() { |
| 41 | - return NULL; |
|
| 41 | + return null; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | $both = 1; |
| 220 | 220 | $agree = 10; |
| 221 | 221 | |
| 222 | - if ( stripos($vote, '3') !== FALSE ) { |
|
| 222 | + if ( stripos($vote, '3') !== false ) { |
|
| 223 | 223 | $agree = 50; |
| 224 | 224 | $absent = 25; |
| 225 | 225 | $both = 25; |
@@ -230,10 +230,10 @@ discard block |
||
| 230 | 230 | 'both' => $both |
| 231 | 231 | ); |
| 232 | 232 | |
| 233 | - if ( stripos($vote, 'aye') !== FALSE ) { |
|
| 233 | + if ( stripos($vote, 'aye') !== false ) { |
|
| 234 | 234 | $scores['aye'] = $agree; |
| 235 | 235 | $scores['no'] = 0; |
| 236 | - } else if ( stripos($vote, 'no') !== FALSE ) { |
|
| 236 | + } else if ( stripos($vote, 'no') !== false ) { |
|
| 237 | 237 | $scores['no'] = $agree; |
| 238 | 238 | $scores['aye'] = 0; |
| 239 | 239 | } else { |
@@ -144,9 +144,15 @@ |
||
| 144 | 144 | $num_votes = 0; |
| 145 | 145 | foreach ($votes as $vote) { |
| 146 | 146 | $vote_dir = $vote['vote']; |
| 147 | - if ( $vote_dir == '' ) continue; |
|
| 148 | - if ( $vote_dir == 'tellno' ) $vote_dir = 'no'; |
|
| 149 | - if ( $vote_dir == 'tellaye' ) $vote_dir = 'aye'; |
|
| 147 | + if ( $vote_dir == '' ) { |
|
| 148 | + continue; |
|
| 149 | + } |
|
| 150 | + if ( $vote_dir == 'tellno' ) { |
|
| 151 | + $vote_dir = 'no'; |
|
| 152 | + } |
|
| 153 | + if ( $vote_dir == 'tellaye' ) { |
|
| 154 | + $vote_dir = 'aye'; |
|
| 155 | + } |
|
| 150 | 156 | |
| 151 | 157 | $num_votes += $vote['num_votes']; |
| 152 | 158 | $score += ($vote['num_votes'] * $weights[$vote_dir]); |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public function __construct($name) { |
| 21 | 21 | // treat Labour and Labour/Co-operative the same as that's how |
| 22 | 22 | // people view them and it'll confuse the results otherwise |
| 23 | - if ( $name == 'Labour/Co-operative' ) { |
|
| 23 | + if ($name == 'Labour/Co-operative') { |
|
| 24 | 24 | $name = 'Labour'; |
| 25 | 25 | } |
| 26 | 26 | $this->name = $name; |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | $score = $position['score']; |
| 75 | 75 | $score_desc = score_to_strongly($score); |
| 76 | 76 | |
| 77 | - if ( $want_score ) { |
|
| 78 | - return array( $score_desc, $score); |
|
| 77 | + if ($want_score) { |
|
| 78 | + return array($score_desc, $score); |
|
| 79 | 79 | } else { |
| 80 | 80 | return $score_desc; |
| 81 | 81 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | ':party' => $this->name |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | - if ( $this->name == 'Labour' ) { |
|
| 117 | + if ($this->name == 'Labour') { |
|
| 118 | 118 | $party_where = '( party = :party OR party = :party2 )'; |
| 119 | 119 | $params = array( |
| 120 | 120 | ':party' => $this->name, |
@@ -144,40 +144,40 @@ discard block |
||
| 144 | 144 | $num_votes = 0; |
| 145 | 145 | foreach ($votes as $vote) { |
| 146 | 146 | $vote_dir = $vote['vote']; |
| 147 | - if ( $vote_dir == '' ) continue; |
|
| 148 | - if ( $vote_dir == 'tellno' ) $vote_dir = 'no'; |
|
| 149 | - if ( $vote_dir == 'tellaye' ) $vote_dir = 'aye'; |
|
| 147 | + if ($vote_dir == '') continue; |
|
| 148 | + if ($vote_dir == 'tellno') $vote_dir = 'no'; |
|
| 149 | + if ($vote_dir == 'tellaye') $vote_dir = 'aye'; |
|
| 150 | 150 | |
| 151 | 151 | $num_votes += $vote['num_votes']; |
| 152 | 152 | $score += ($vote['num_votes'] * $weights[$vote_dir]); |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | $total_votes += $num_votes; |
| 156 | - $max_score += $num_votes * max( array_values( $weights ) ); |
|
| 156 | + $max_score += $num_votes * max(array_values($weights)); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if ( $total_votes == 0 ) { |
|
| 159 | + if ($total_votes == 0) { |
|
| 160 | 160 | return null; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // this implies that all the divisions in the policy have a policy |
| 164 | 164 | // position of absent so we set weight to -1 to indicate we can't |
| 165 | 165 | // really say what the parties position is. |
| 166 | - if ( $max_score == 0 ) { |
|
| 166 | + if ($max_score == 0) { |
|
| 167 | 167 | $weight = -1; |
| 168 | 168 | } else { |
| 169 | - $weight = 1 - ( $score/$max_score ); |
|
| 169 | + $weight = 1 - ($score / $max_score); |
|
| 170 | 170 | } |
| 171 | 171 | $score_desc = score_to_strongly($weight); |
| 172 | 172 | |
| 173 | - if ( $want_score ) { |
|
| 174 | - return array( $score_desc, $weight); |
|
| 173 | + if ($want_score) { |
|
| 174 | + return array($score_desc, $weight); |
|
| 175 | 175 | } else { |
| 176 | 176 | return $score_desc; |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - public function cache_position( $position ) { |
|
| 180 | + public function cache_position($position) { |
|
| 181 | 181 | $this->db->query( |
| 182 | 182 | "REPLACE INTO partypolicy |
| 183 | 183 | (party, house, policy_id, score) |
@@ -197,9 +197,9 @@ discard block |
||
| 197 | 197 | return $positions; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - foreach ( $policies->getPolicies() as $policy_id => $policy_text ) { |
|
| 201 | - list( $position, $score ) = $this->$method($policy_id, true); |
|
| 202 | - if ( $position === null ) { |
|
| 200 | + foreach ($policies->getPolicies() as $policy_id => $policy_text) { |
|
| 201 | + list($position, $score) = $this->$method($policy_id, true); |
|
| 202 | + if ($position === null) { |
|
| 203 | 203 | continue; |
| 204 | 204 | } |
| 205 | 205 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | $both = 1; |
| 220 | 220 | $agree = 10; |
| 221 | 221 | |
| 222 | - if ( stripos($vote, '3') !== FALSE ) { |
|
| 222 | + if (stripos($vote, '3') !== FALSE) { |
|
| 223 | 223 | $agree = 50; |
| 224 | 224 | $absent = 25; |
| 225 | 225 | $both = 25; |
@@ -230,10 +230,10 @@ discard block |
||
| 230 | 230 | 'both' => $both |
| 231 | 231 | ); |
| 232 | 232 | |
| 233 | - if ( stripos($vote, 'aye') !== FALSE ) { |
|
| 233 | + if (stripos($vote, 'aye') !== FALSE) { |
|
| 234 | 234 | $scores['aye'] = $agree; |
| 235 | 235 | $scores['no'] = 0; |
| 236 | - } else if ( stripos($vote, 'no') !== FALSE ) { |
|
| 236 | + } else if (stripos($vote, 'no') !== FALSE) { |
|
| 237 | 237 | $scores['no'] = $agree; |
| 238 | 238 | $scores['aye'] = 0; |
| 239 | 239 | } else { |