diff --git a/classes/AlertView/Simple.php b/classes/AlertView/Simple.php index ba41c51c61..f25057a966 100644 --- a/classes/AlertView/Simple.php +++ b/classes/AlertView/Simple.php @@ -6,7 +6,7 @@ class Simple extends \MySociety\TheyWorkForYou\AlertView { public function display() { - $data = array(); + $data = []; $data['recent_election'] = false; if ($this->user->loggedin()) { $data['user_signed_in'] = true; @@ -44,10 +44,10 @@ public function display() private function getPersonFromPostcode($postcode) { - $args = array( + $args = [ 'postcode' => $postcode, 'house' => 1, - ); + ]; $member = new \MySociety\TheyWorkForYou\Member($args); return $member; @@ -71,23 +71,23 @@ private function validateDetails($email, $postcode) private function createAlertForPostCode($email, $postcode) { if (!$this->validateDetails($email, $postcode)) { - return array('invalid-postcode-or-email' => true); + return ['invalid-postcode-or-email' => true]; } try { $person = $this->getPersonFromPostcode($postcode); } catch (\MySociety\TheyWorkForYou\MemberException $e) { - return array('bad-constituency' => true); + return ['bad-constituency' => true]; } - $details = array( + $details = [ 'email' => $email, 'pid' => $person->person_id, 'pc' => $postcode, 'confirm_base' => 'https://' . DOMAIN . '/alert/by-postcode?confirmed=', - ); + ]; - $data = array(); + $data = []; $not_logged_in = $this->user->loggedin ? false : true; $result = $this->alert->add($details, $not_logged_in); @@ -121,8 +121,8 @@ private function replaceAlert($confirmation) $existing = $this->alert->fetch_by_token($confirmation); preg_match('/speaker:(\d+)/', $existing['criteria'], $matches); $old_mp_id = $matches[1]; - $old_mp = new \MySociety\TheyWorkForYou\Member(array( 'person_id' => $old_mp_id )); - $new_mp = new \MySociety\TheyWorkForYou\Member(array( 'constituency' => $old_mp->constituency, 'house' => 1 )); + $old_mp = new \MySociety\TheyWorkForYou\Member([ 'person_id' => $old_mp_id ]); + $new_mp = new \MySociety\TheyWorkForYou\Member([ 'constituency' => $old_mp->constituency, 'house' => 1 ]); $q = $this->db->query( "SELECT alert_id, criteria, registrationtoken FROM alerts @@ -130,10 +130,10 @@ private function replaceAlert($confirmation) AND criteria LIKE :criteria AND confirmed = 1 AND deleted = 0", - array( + [ ':email' => $existing['email'], ':criteria' => '%speaker:' . $old_mp_id . '%', - ), + ], ); foreach ($q as $row) { @@ -141,11 +141,11 @@ private function replaceAlert($confirmation) $this->alert->token_checked = null; $other_criteria = trim(preg_replace('/speaker:\d+/', '', $row['criteria'])); - $details = array( + $details = [ 'email' => $existing['email'], 'pid' => $new_mp->person_id, 'pc' => '', - ); + ]; if ($other_criteria) { $details['keyword'] = $other_criteria; } @@ -154,10 +154,10 @@ private function replaceAlert($confirmation) $this->alert->add($details, false); } - return array( + return [ 'signedup_no_confirm' => true, 'new_mp' => $new_mp->full_name(), - ); + ]; } private function isEmailSignedUpForPostCode($email, $postcode) @@ -178,27 +178,27 @@ private function isEmailSignedUpForPostCode($email, $postcode) private function getNewMP($confirmation) { if (!$confirmation) { - return array(); + return []; } $existing = $this->alert->fetch_by_token($confirmation); preg_match('/speaker:(\d+)/', $existing['criteria'], $matches); $criteria = $matches[1]; - $old_mp = new \MySociety\TheyWorkForYou\Member(array( 'person_id' => $criteria )); - $new_mp = new \MySociety\TheyWorkForYou\Member(array( 'constituency' => $old_mp->constituency, 'house' => 1 )); + $old_mp = new \MySociety\TheyWorkForYou\Member([ 'person_id' => $criteria ]); + $new_mp = new \MySociety\TheyWorkForYou\Member([ 'constituency' => $old_mp->constituency, 'house' => 1 ]); if ($this->alert->fetch_by_mp($existing['email'], $new_mp->person_id)) { - $data = array( + $data = [ 'already_signed_up' => true, 'old_mp' => $old_mp->full_name(), 'mp_name' => $new_mp->full_name(), - ); + ]; } else { - $data = array( + $data = [ 'old_mp' => $old_mp->full_name(), 'new_mp' => $new_mp->full_name(), - ); + ]; } $data['update'] = true; diff --git a/classes/AlertView/Standard.php b/classes/AlertView/Standard.php index 3035f0a028..95bef4de07 100644 --- a/classes/AlertView/Standard.php +++ b/classes/AlertView/Standard.php @@ -15,7 +15,7 @@ class Standard extends \MySociety\TheyWorkForYou\AlertView public function __construct($THEUSER = null) { parent::__construct($THEUSER); - $this->data = array(); + $this->data = []; } public function display() @@ -117,7 +117,7 @@ private function checkInput() { global $SEARCHENGINE; - $errors = array(); + $errors = []; // Check each of the things the user has input. // If there is a problem with any of them, set an entry in the $errors array. @@ -166,15 +166,15 @@ private function searchForConstituenciesAndMembers() // Do the search if ($this->data['alertsearch']) { $this->data['members'] = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookupWithNames($this->data['alertsearch'], true); - list($this->data['constituencies'], $this->data['valid_postcode']) = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($this->data['alertsearch']); + [$this->data['constituencies'], $this->data['valid_postcode']] = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($this->data['alertsearch']); } else { - $this->data['members'] = array(); + $this->data['members'] = []; } # If the above search returned one result for constituency # search by postcode, use it immediately if (isset($this->data['constituencies']) && count($this->data['constituencies']) == 1 && $this->data['valid_postcode']) { - $MEMBER = new \MEMBER(array('constituency' => $this->data['constituencies'][0], 'house' => 1)); + $MEMBER = new \MEMBER(['constituency' => $this->data['constituencies'][0], 'house' => 1]); $this->data['pid'] = $MEMBER->person_id(); $this->data['pc'] = $this->data['alertsearch']; unset($this->data['constituencies']); @@ -182,10 +182,10 @@ private function searchForConstituenciesAndMembers() } if (isset($this->data['constituencies'])) { - $cons = array(); + $cons = []; foreach ($this->data['constituencies'] as $constituency) { try { - $MEMBER = new \MEMBER(array('constituency' => $constituency, 'house' => 1)); + $MEMBER = new \MEMBER(['constituency' => $constituency, 'house' => 1]); $cons[$constituency] = $MEMBER; } catch (\MySociety\TheyWorkForYou\MemberException $e) { // do nothing @@ -254,7 +254,7 @@ private function formatSearchTerms() private function checkForCommonMistakes() { - $mistakes = array(); + $mistakes = []; if (strstr($this->data['alertsearch'], ',') > -1) { $mistakes['multiple'] = 1; } @@ -277,7 +277,7 @@ private function formatSearchMemberData() try { $postcode = $this->data['postcode']; - $MEMBER = new \MEMBER(array('postcode' => $postcode)); + $MEMBER = new \MEMBER(['postcode' => $postcode]); // move the postcode to the front just to be tidy $tidy_alertsearch = $postcode . " " . trim(str_replace("$postcode", "", $this->data['alertsearch'])); $alertsearch_display = str_replace("$postcode ", "", $tidy_alertsearch); @@ -289,11 +289,11 @@ private function formatSearchMemberData() if (isset($this->data['mistakes']['postcode_and'])) { $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode); if (isset($constituencies['SPC'])) { - $MEMBER = new \MEMBER(array('constituency' => $constituencies['SPC'], 'house' => HOUSE_TYPE_SCOTLAND)); + $MEMBER = new \MEMBER(['constituency' => $constituencies['SPC'], 'house' => HOUSE_TYPE_SCOTLAND]); $this->data['scottish_alertsearch'] = str_replace("$postcode", "speaker:" . $MEMBER->person_id, $tidy_alertsearch); $this->data['scottish_member'] = $MEMBER; } elseif (isset($constituencies['WAC'])) { - $MEMBER = new \MEMBER(array('constituency' => $constituencies['WAC'], 'house' => HOUSE_TYPE_WALES)); + $MEMBER = new \MEMBER(['constituency' => $constituencies['WAC'], 'house' => HOUSE_TYPE_WALES]); $this->data['welsh_alertsearch'] = str_replace("$postcode", "speaker:" . $MEMBER->person_id, $tidy_alertsearch); $this->data['welsh_member'] = $MEMBER; } @@ -304,7 +304,7 @@ private function formatSearchMemberData() } if ($this->data['pid']) { - $MEMBER = new \MEMBER(array('person_id' => $this->data['pid'])); + $MEMBER = new \MEMBER(['person_id' => $this->data['pid']]); $this->data['pid_member'] = $MEMBER; } @@ -316,10 +316,10 @@ private function formatSearchMemberData() private function setUserData() { $this->data['current_mp'] = false; - $this->data['alerts'] = array(); + $this->data['alerts'] = []; if ($this->data['email_verified']) { if ($this->user->postcode()) { - $current_mp = new \MEMBER(array('postcode' => $this->user->postcode())); + $current_mp = new \MEMBER(['postcode' => $this->user->postcode()]); if (!$this->alert->fetch_by_mp($this->data['email'], $current_mp->person_id())) { $this->data['current_mp'] = $current_mp; } diff --git a/classes/Data.php b/classes/Data.php index 14dc1683af..46a68af464 100644 --- a/classes/Data.php +++ b/classes/Data.php @@ -86,10 +86,10 @@ public function set_section() public function page_metadata($page, $key) { return $this->getMetadata( - array( + [ 'page' => $page, 'key' => $key, - ), + ], 'page', ); } @@ -104,10 +104,10 @@ public function page_metadata($page, $key) public function section_metadata($section, $key) { return $this->getMetadata( - array( + [ 'section' => $section, 'key' => $key, - ), + ], 'section', ); } @@ -122,7 +122,7 @@ public function section_metadata($section, $key) public function set_page_metadata($page, $key, $value) { - $this->setMetadata(array("page" => $page, "key" => $key, "value" => $value)); + $this->setMetadata(["page" => $page, "key" => $key, "value" => $value]); } /** @@ -135,7 +135,7 @@ public function set_page_metadata($page, $key, $value) public function set_section_metadata($section, $key, $value) { - $this->setMetadata(array("section" => $section, "key" => $key, "value" => $value)); + $this->setMetadata(["section" => $section, "key" => $key, "value" => $value]); } /** diff --git a/classes/Db/Query.php b/classes/Db/Query.php index 7557ba91bd..164e3b7b82 100644 --- a/classes/Db/Query.php +++ b/classes/Db/Query.php @@ -40,7 +40,7 @@ class Query implements \IteratorAggregate, \ArrayAccess { private $success = true; private $rows = null; - private $data = array(); + private $data = []; private $insert_id = null; private $affected_rows = null; @@ -120,7 +120,7 @@ public function query($sql = "", $params = null) } $this->affected_rows = $pdoStatement->rowCount(); - twfy_debug("SQLRESULT", array($this, 'displayResult')); + twfy_debug("SQLRESULT", [$this, 'displayResult']); // mysql_free_result($q); } } @@ -199,7 +199,7 @@ public function row($row_index) if ($this->success && $this->rows > 0) { return $this->data[$row_index]; } - return array(); + return []; } public function exists() diff --git a/classes/Dissolution.php b/classes/Dissolution.php index 6b7527993c..84dd3eaa42 100644 --- a/classes/Dissolution.php +++ b/classes/Dissolution.php @@ -6,10 +6,10 @@ class Dissolution { public static function dates() { - $out = array(); + $out = []; $dates = array_filter(explode(',', DISSOLUTION_DATE)); foreach ($dates as $houseanddate) { - list($house, $date) = explode(':', $houseanddate); + [$house, $date] = explode(':', $houseanddate); $out[$house] = $date; } return $out; @@ -21,16 +21,16 @@ public static function db() return null; } - $params = array(); - $query = array(); + $params = []; + $query = []; foreach ($dates as $house => $date) { $params[":dissdate$house"] = $date; $query[] = "left_house = :dissdate$house"; } - return array( + return [ 'query' => '(' . join(' OR ', $query) . ')', 'params' => $params, - ); + ]; } } diff --git a/classes/Divisions.php b/classes/Divisions.php index 10edff9562..31b117d509 100644 --- a/classes/Divisions.php +++ b/classes/Divisions.php @@ -47,7 +47,7 @@ public static function getMostRecentDivisionDate() GROUP BY policy_id", ); - $policy_maxes = array(); + $policy_maxes = []; foreach ($q as $row) { $policy_maxes[$row['policy_id']] = $row['recent']; } @@ -65,14 +65,14 @@ public function getRecentDivisions($number = 20, $houses = null) $select = ''; $order = 'ORDER BY division_date DESC, division_number DESC'; $limit = 'LIMIT :count'; - $params = array( + $params = [ ':count' => $number, - ); + ]; $where = []; if ($houses) { if (is_string($houses)) { - $houses = array( $houses ); + $houses = [ $houses ]; } $where[] = 'house IN ("' . implode('", "', $houses) . '")'; } @@ -98,7 +98,7 @@ public function getRecentDivisions($number = 20, $houses = null) $params, ); - $divisions = array(); + $divisions = []; foreach ($q as $division) { $data = $this->getParliamentDivisionDetails($division); @@ -124,7 +124,7 @@ public function getRecentDivisions($number = 20, $houses = null) $divisions[] = $data; } - return array('divisions' => $divisions); + return ['divisions' => $divisions]; } /** @@ -160,10 +160,10 @@ public function getRecentDebatesWithDivisions($number = 20, $majors = null) GROUP BY h.subsection_id ORDER BY h.hdate DESC, h.hpos DESC LIMIT :count", - array(':count' => $number), + [':count' => $number], ); - $debates = array(); + $debates = []; foreach ($q as $debate) { $debate_gid = fix_gid_from_db($debate['debate_gid']); $anchor = ''; @@ -171,7 +171,7 @@ public function getRecentDebatesWithDivisions($number = 20, $majors = null) $anchor = '#g' . gid_to_anchor(fix_gid_from_db($debate['gid'])); } $url = new Url($hansardmajors[$debate['major']]['page']); - $url->insert(array('gid' => $debate_gid)); + $url->insert(['gid' => $debate_gid]); $debates[] = [ 'url' => $url->generate() . $anchor, 'title' => "$debate[section_body] : $debate[subsection_body]", @@ -184,9 +184,9 @@ public function getRecentDebatesWithDivisions($number = 20, $majors = null) public function getRecentDivisionsForPolicies($policies, $number = 20) { - $args = array(':number' => $number); + $args = [':number' => $number]; - $quoted = array(); + $quoted = []; foreach ($policies as $policy) { $quoted[] = $this->db->quote($policy); } @@ -202,7 +202,7 @@ public function getRecentDivisionsForPolicies($policies, $number = 20) $args, ); - $divisions = array(); + $divisions = []; foreach ($q as $row) { $divisions[] = $this->getParliamentDivisionDetails($row); } @@ -227,7 +227,7 @@ public function getRecentDivisionsForPolicies($policies, $number = 20) public function getMemberDivisionsForPolicy($policyID = null) { $where_extra = ''; - $args = array(':person_id' => $this->member->person_id); + $args = [':person_id' => $this->member->person_id]; if ($policyID) { $where_extra = 'AND policy_id = :policy_id'; $args[':policy_id'] = $policyID; @@ -246,9 +246,9 @@ public function getMemberDivisionsForPolicy($policyID = null) public function getMemberDivisionDetails($strong_only = false) { - $args = array(':person_id' => $this->member->person_id); + $args = [':person_id' => $this->member->person_id]; - $policy_divisions = array(); + $policy_divisions = []; if ($strong_only) { $where_extra = "AND (policy_vote = 'no3' OR policy_vote = 'aye3')"; } else { @@ -268,12 +268,12 @@ public function getMemberDivisionDetails($strong_only = false) $policy_id = $row['policy_id']; if (!array_key_exists($policy_id, $policy_divisions)) { - $summary = array( + $summary = [ 'max' => $row['latest'], 'min' => $row['earliest'], 'total' => $row['total'], 'for' => 0, 'against' => 0, 'absent' => 0, 'both' => 0, 'tell' => 0, - ); + ]; $policy_divisions[$policy_id] = $summary; } @@ -328,9 +328,9 @@ public function getMemberDivisionDetails($strong_only = false) public function getDivisionByGid($gid) { - $args = array( + $args = [ ':gid' => $gid, - ); + ]; $q = $this->db->query("SELECT * FROM divisions WHERE gid = :gid", $args)->first(); if (!$q) { @@ -342,9 +342,9 @@ public function getDivisionByGid($gid) public function getDivisionResults($division_id) { - $args = array( + $args = [ ':division_id' => $division_id, - ); + ]; $q = $this->db->query("SELECT * FROM divisions WHERE division_id = :division_id", $args)->first(); if (!$q) { @@ -376,19 +376,19 @@ private function _division_data($row) $args, ); - $votes = array( - 'yes_votes' => array(), - 'no_votes' => array(), - 'absent_votes' => array(), - 'both_votes' => array(), - ); + $votes = [ + 'yes_votes' => [], + 'no_votes' => [], + 'absent_votes' => [], + 'both_votes' => [], + ]; - $party_breakdown = array( - 'yes_votes' => array(), - 'no_votes' => array(), - 'absent_votes' => array(), - 'both_votes' => array(), - ); + $party_breakdown = [ + 'yes_votes' => [], + 'no_votes' => [], + 'absent_votes' => [], + 'both_votes' => [], + ]; # Sort Lords specially $data = $q->fetchAll(); @@ -397,7 +397,7 @@ private function _division_data($row) } foreach ($data as $vote) { - $detail = array( + $detail = [ 'person_id' => $vote['person_id'], 'name' => ucfirst(member_full_name( $args['house'], @@ -409,7 +409,7 @@ private function _division_data($row) 'party' => $vote['party'], 'proxy' => false, 'teller' => false, - ); + ]; if (strpos($vote['vote'], 'tell') !== false) { $detail['teller'] = true; @@ -455,7 +455,7 @@ private function _division_data($row) } foreach ($party_breakdown as $vote => $parties) { - $summary = array(); + $summary = []; foreach ($parties as $party => $count) { array_push($summary, "$party: $count"); } @@ -475,10 +475,10 @@ private function _division_data($row) public function getDivisionResultsForMember($division_id, $person_id) { - $args = array( + $args = [ ':division_id' => $division_id, ':person_id' => $person_id, - ); + ]; $q = $this->db->query( "SELECT division_id, division_title, yes_text, no_text, division_date, division_number, gid, vote FROM divisions JOIN persondivisionvotes USING(division_id) @@ -501,10 +501,10 @@ public function generateSummary($votes) $max = $votes['max']; $min = $votes['min']; - $actions = array( + $actions = [ $votes['for'] . ' ' . make_plural('vote', $votes['for']) . ' for', $votes['against'] . ' ' . make_plural('vote', $votes['against']) . ' against', - ); + ]; if ($votes['agreements_for']) { $actions[] = $votes['agreements_for'] . ' ' . make_plural('agreement', $votes['agreements_for']) . ' for'; @@ -557,7 +557,7 @@ public function getAllMemberDivisionsByPolicy() */ public function getRecentMemberDivisions($number = 20) { - $args = array(':person_id' => $this->member->person_id, ':number' => $number); + $args = [':person_id' => $this->member->person_id, ':number' => $number]; $q = $this->db->query( "SELECT * FROM persondivisionvotes @@ -567,7 +567,7 @@ public function getRecentMemberDivisions($number = 20) $args, ); - $divisions = array(); + $divisions = []; foreach ($q as $row) { $divisions[] = $this->getDivisionDetails($row); } @@ -627,7 +627,7 @@ private function getBasicDivisionDetails($row, $vote) $yes_text = $row['yes_text']; $no_text = $row['no_text']; - $division = array( + $division = [ 'division_id' => $row['division_id'], 'date' => $row['division_date'], 'gid' => fix_gid_from_db($row['gid']), @@ -635,7 +635,7 @@ private function getBasicDivisionDetails($row, $vote) 'text' => $this->constructVoteDescription($vote, $yes_text, $no_text, $row['division_title']), 'has_description' => $yes_text && $no_text, 'vote' => $vote, - ); + ]; if ($row['gid']) { $division['debate_url'] = $this->divisionUrlFromGid($row['gid']); @@ -653,17 +653,17 @@ private function getBasicDivisionDetails($row, $vote) "SELECT policy_id, direction FROM policydivisions WHERE division_id = :division_id", - array(':division_id' => $row['division_id']), + [':division_id' => $row['division_id']], ); - $division['related_policies'] = array(); + $division['related_policies'] = []; $policy_lookup = $this->policies->getPolicies(); foreach ($q as $policy) { - $division['related_policies'][] = array( + $division['related_policies'][] = [ 'policy_id' => $policy['policy_id'], 'policy_title' => preg_replace('#]*>#', '', $policy_lookup[$policy['policy_id']]), 'direction' => $policy['direction'], - ); + ]; } if (array_key_exists('direction', $row)) { @@ -698,7 +698,7 @@ private function getParliamentDivisionDetails($row) private function divisionsByPolicy($q) { - $policies = array(); + $policies = []; # iterate through each division, and adds it to an array of policies # if there is only one policy being queried, it will be an array of 1 @@ -707,10 +707,10 @@ private function divisionsByPolicy($q) # if this policy hasn't come up yet, create the key for it if (!array_key_exists($policy_id, $policies)) { - $policies[$policy_id] = array( + $policies[$policy_id] = [ 'policy_id' => $policy_id, - 'divisions' => array(), - ); + 'divisions' => [], + ]; $policies[$policy_id]['desc'] = $this->policies->getPolicies()[$policy_id]; $policies[$policy_id]['header'] = $this->policies->getPolicyDetails($policy_id); if ($this->positions) { @@ -733,13 +733,13 @@ private function divisionUrlFromGid($gid) $gid = get_canonical_gid($gid); - $q = $this->db->query("SELECT gid, major FROM hansard WHERE epobject_id = ( SELECT subsection_id FROM hansard WHERE gid = :gid )", array( ':gid' => $gid ))->first(); + $q = $this->db->query("SELECT gid, major FROM hansard WHERE epobject_id = ( SELECT subsection_id FROM hansard WHERE gid = :gid )", [ ':gid' => $gid ])->first(); if (!$q) { return ''; } $parent_gid = fix_gid_from_db($q['gid']); $url = new Url($hansardmajors[$q['major']]['page']); - $url->insert(array('gid' => $parent_gid)); + $url->insert(['gid' => $parent_gid]); return $url->generate() . '#g' . gid_to_anchor(fix_gid_from_db($gid)); } } diff --git a/classes/EditQueue.php b/classes/EditQueue.php index 7fdd2df1dc..256e5df8ff 100644 --- a/classes/EditQueue.php +++ b/classes/EditQueue.php @@ -163,17 +163,17 @@ public function approve($data) (epobject_id, type, visible) VALUES (:id, :type, :enabled);', - array( + [ ':id' => $q->insert_id(), ':type' => EPTYPE_GLOSSARY, ':enabled' => 1, - ), + ], ); // Again, no point carrying on if this fails, // so remove the previous entry if (!$q->success()) { print "glossary trouble!"; - $this->db->query('DELETE FROM epobject WHERE epobject_id=:id ;', array(':id' => $previous_insert_id)); + $this->db->query('DELETE FROM epobject WHERE epobject_id=:id ;', [':id' => $previous_insert_id]); return false; } break; @@ -191,13 +191,13 @@ public function approve($data) approved=:approved, decided=:timestamp WHERE edit_id=:approval_id ;', - array( + [ ':current' => $this->current_epobject_id, ':editor' => addslashes($THEUSER->user_id()), ':approved' => '1', ':timestamp' => $timestamp, ':approval_id' => $approval_id, - ), + ], ); if (!$q->success()) { break; @@ -289,15 +289,15 @@ public function display() foreach ($this->pending as $editqueue_id => $pender) { $URL = new Url('admin_glossary_pending'); - $URL->insert(array('approve' => $editqueue_id)); + $URL->insert(['approve' => $editqueue_id]); $approve_link = $URL->generate('url'); $URL = new Url('admin_glossary_pending'); - $URL->insert(array('modify' => $editqueue_id)); + $URL->insert(['modify' => $editqueue_id]); $modify_link = $URL->generate('url'); $URL = new Url('admin_glossary_pending'); - $URL->insert(array('decline' => $editqueue_id)); + $URL->insert(['decline' => $editqueue_id]); $decline_link = $URL->generate('url'); ?>
diff --git a/classes/FacebookLogin.php b/classes/FacebookLogin.php index 40609f103d..9e0fa550a4 100644 --- a/classes/FacebookLogin.php +++ b/classes/FacebookLogin.php @@ -43,7 +43,7 @@ public function handleFacebookRedirect() { $helper = $this->getFacebookObject()->getRedirectLoginHelper(); - $data = array('login_url' => $this->getLoginURL()); + $data = ['login_url' => $this->getLoginURL()]; try { $accessToken = $helper->getAccessToken(); @@ -58,7 +58,7 @@ public function handleFacebookRedirect() $token = $this->checkAccessToken($accessToken); if ($token) { - return array('token' => $token); + return ['token' => $token]; } else { $data['error'] = 'Problem getting Facebook token'; return $data; @@ -134,7 +134,7 @@ public function createUser($accessToken, $user) $first_name = array_shift($name_parts); $last_name = implode(' ', $name_parts); global $THEUSER; - $details = array( + $details = [ 'firstname' => $first_name, 'lastname' => $last_name, 'email' => $user['email'], @@ -145,7 +145,7 @@ public function createUser($accessToken, $user) 'optin' => false, 'mp_alert' => false, 'facebook_id' => $user['id'], - ); + ]; $added = $THEUSER->add($details, false); if ($added) { twfy_debug("THEUSER", "Added new user from facebook details " . $THEUSER->user_id()); @@ -163,7 +163,7 @@ public function updateUser($user) $first_name = array_shift($name_parts); $last_name = implode(' ', $name_parts); - $details = array( + $details = [ 'firstname' => $first_name, 'lastname' => $last_name, 'email' => $user['email'], @@ -171,7 +171,7 @@ public function updateUser($user) 'url' => $THEUSER->url(), 'optin' => $THEUSER->optin(), 'password' => '', - ); + ]; $THEUSER->update_self_no_confirm($details); } diff --git a/classes/Gid.php b/classes/Gid.php index 653c9a0ece..2028f15e50 100644 --- a/classes/Gid.php +++ b/classes/Gid.php @@ -17,7 +17,7 @@ public function checkForRedirect() { $q = $this->db->query( "SELECT gid_to FROM gidredirect WHERE gid_from = :gid", - array(':gid' => $this->gid), + [':gid' => $this->gid], )->first(); if (!$q) { @@ -27,7 +27,7 @@ public function checkForRedirect() $gid = $q['gid_to']; $q = $this->db->query( "SELECT gid_to FROM gidredirect WHERE gid_from = :gid", - array(':gid' => $gid), + [':gid' => $gid], )->first(); } while ($q); return $gid; diff --git a/classes/Homepage.php b/classes/Homepage.php index a3b2fb84a3..85e7b35b73 100644 --- a/classes/Homepage.php +++ b/classes/Homepage.php @@ -10,16 +10,16 @@ class Homepage protected $cons_type = 'WMC'; protected $mp_url = 'yourmp'; protected $page = 'overview'; - protected $houses = array(1, 101); + protected $houses = [1, 101]; - protected $recent_types = array( - 'DEBATELIST' => array('recent_debates', 'debatesfront', 'Commons debates'), - 'LORDSDEBATELIST' => array('recent_debates', 'lordsdebatesfront', 'Lords debates'), - 'WHALLLIST' => array('recent_debates', 'whallfront', 'Westminster Hall debates'), - 'WMSLIST' => array('recent_wms', 'wmsfront', 'Written ministerial statements'), - 'WRANSLIST' => array('recent_wrans', 'wransfront', 'Written answers'), - 'StandingCommittee' => array('recent_pbc_debates', 'pbcfront', 'Public Bill committees'), - ); + protected $recent_types = [ + 'DEBATELIST' => ['recent_debates', 'debatesfront', 'Commons debates'], + 'LORDSDEBATELIST' => ['recent_debates', 'lordsdebatesfront', 'Lords debates'], + 'WHALLLIST' => ['recent_debates', 'whallfront', 'Westminster Hall debates'], + 'WMSLIST' => ['recent_wms', 'wmsfront', 'Written ministerial statements'], + 'WRANSLIST' => ['recent_wrans', 'wransfront', 'Written answers'], + 'StandingCommittee' => ['recent_pbc_debates', 'pbcfront', 'Public Bill committees'], + ]; public function __construct() { @@ -31,7 +31,7 @@ public function display() global $this_page; $this_page = $this->page; - $data = array(); + $data = []; $common = new Common(); $dissolution = Dissolution::dates(); @@ -71,16 +71,16 @@ protected function getEditorialContent() $related = $featured->get_related(); $item = $this->getFeaturedDebate($gid, $title, $context, $related); } else { - $item = $debatelist->display('recent_debates', array('days' => 7, 'num' => 1), 'none'); + $item = $debatelist->display('recent_debates', ['days' => 7, 'num' => 1], 'none'); if (isset($item['data']) && count($item['data'])) { $item = $item['data'][0]; $more_url = new Url('debates'); $item['more_url'] = $more_url->generate(); $item['desc'] = 'Commons Debates'; - $item['related'] = array(); + $item['related'] = []; $item['featured'] = false; } else { - $item = array(); + $item = []; } } @@ -97,16 +97,16 @@ public function getFeaturedDebate($gid, $title, $context, $related) $debatelist = new \DEBATELIST(); } - $item = $debatelist->display('featured_gid', array('gid' => $gid), 'none'); + $item = $debatelist->display('featured_gid', ['gid' => $gid], 'none'); $item = $item['data']; $item['headline'] = $title; $item['context'] = $context; $item['featured'] = true; - $related_debates = array(); + $related_debates = []; foreach ($related as $related_gid) { if ($related_gid) { - $related_item = $debatelist->display('featured_gid', array('gid' => $related_gid), 'none'); + $related_item = $debatelist->display('featured_gid', ['gid' => $related_gid], 'none'); $related_debates[] = $related_item['data']; } } @@ -128,29 +128,29 @@ private function getRecentDivisions() protected function getURLs() { - $urls = array(); + $urls = []; return $urls; } protected function getDebatesData() { - $debates = array(); // holds the most recent data there is data for, indexed by type + $debates = []; // holds the most recent data there is data for, indexed by type - $recent_content = array(); + $recent_content = []; foreach ($this->recent_types as $class => $recent) { $class = "\\$class"; $instance = new $class(); $more_url = new Url($recent[1]); if ($recent[0] == 'recent_pbc_debates') { - $content = array( 'data' => $instance->display($recent[0], array('num' => 5), 'none') ); + $content = [ 'data' => $instance->display($recent[0], ['num' => 5], 'none') ]; } else { - $content = $instance->display($recent[0], array('days' => 7, 'num' => 1), 'none'); + $content = $instance->display($recent[0], ['days' => 7, 'num' => 1], 'none'); if (isset($content['data']) && count($content['data'])) { $content = $content['data'][0]; } else { - $content = array(); + $content = []; } } if ($content) { diff --git a/classes/Member.php b/classes/Member.php index 386226d3be..3d4a8589e3 100644 --- a/classes/Member.php +++ b/classes/Member.php @@ -31,14 +31,14 @@ public function isDead() // This member has left a house, and might be dead. See if they are. // Types of house to test for death. - $house_types = array( + $house_types = [ HOUSE_TYPE_COMMONS, HOUSE_TYPE_LORDS, HOUSE_TYPE_SCOTLAND, HOUSE_TYPE_NI, HOUSE_TYPE_WALES, HOUSE_TYPE_LONDON_ASSEMBLY, - ); + ]; foreach ($house_types as $house_type) { @@ -84,7 +84,7 @@ public function cohortPartyComparisonDirection() // MPs who have switched parties but should be compared against their // current party can go here. - $use_last_party = array(10172, 14031, 25873, 10218); + $use_last_party = [10172, 14031, 25873, 10218]; if (in_array($person_id, $use_last_party)) { $direction = "last"; @@ -126,8 +126,8 @@ public function cohortParty($house = HOUSE_TYPE_COMMONS) and person_id = :person_id and party != '' order by entered_house - " . $direction, array(":house" => $house, - ":person_id" => $person_id))->first(); + " . $direction, [":house" => $house, + ":person_id" => $person_id])->first(); if ($row) { $party = $row["party"]; if ($party == 'Labour/Co-operative') { @@ -234,9 +234,9 @@ public function image() $is_lord = $this->house(HOUSE_TYPE_LORDS); if ($is_lord) { - list($image, $size) = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); + [$image, $size] = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); } else { - list($image, $size) = Utility\Member::findMemberImage($this->person_id(), false, true); + [$image, $size] = Utility\Member::findMemberImage($this->person_id(), false, true); } // We can determine if the image exists or not by testing if size is set @@ -246,11 +246,11 @@ public function image() $exists = false; } - return array( + return [ 'url' => $image, 'size' => $size, 'exists' => $exists, - ); + ]; } @@ -295,7 +295,7 @@ function ($a, $b) { public function offices($include_only = null, $ignore_committees = false) { - $out = array(); + $out = []; if (array_key_exists('office', $this->extra_info())) { $office = $this->extra_info(); @@ -359,7 +359,7 @@ public function getOtherPartiesString() if (!empty($this->other_parties) && $this->party != 'Speaker' && $this->party != 'Deputy Speaker') { $output = 'Party was '; - $other_parties = array(); + $other_parties = []; foreach ($this->other_parties as $r) { $other_parties[] = $r['from'] . ' until ' . format_date($r['date'], SHORTDATEFORMAT); } @@ -401,7 +401,7 @@ public function getOtherConstituenciesString() */ public function getEnterLeaveStrings() { - $output = array(); + $output = []; $output[] = $this->entered_house_line(HOUSE_TYPE_LORDS, gettext('House of Lords')); @@ -479,7 +479,7 @@ private function left_house_line($house, $house_name) public function getPartyPolicyDiffs($partyCohort, $policiesList, $positions) { - $policy_diffs = array(); + $policy_diffs = []; $party_positions = $partyCohort->getAllPolicyPositions($policiesList); if (!$party_positions) { @@ -543,7 +543,7 @@ public static function getRegionalList($postcode, $house, $type) { $db = new \ParlDB(); - $mreg = array(); + $mreg = []; $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode); if (isset($constituencies[$type])) { $cons_name = $constituencies[$type]; @@ -558,29 +558,29 @@ public static function getRegionalList($postcode, $house, $type) AND left_house <= end_date"; $q = $db->query( "$query_base AND left_reason = 'still_in_office'", - array( + [ ':house' => $house, ':cons_name' => $cons_name, - ), + ], ); if (!$q->rows() && ($dissolution = Dissolution::db())) { $q = $db->query( "$query_base AND $dissolution[query]", - array( + [ ':house' => $house, ':cons_name' => $cons_name, - ) + $dissolution['params'], + ] + $dissolution['params'], ); } foreach ($q as $row) { $name = member_full_name($house, $row['title'], $row['given_name'], $row['family_name'], $row['lordofname']); - $mreg[] = array( + $mreg[] = [ 'person_id' => $row['person_id'], 'name' => $name, 'house' => $row['house'], 'constituency' => gettext($row['constituency']), - ); + ]; } } diff --git a/classes/Model/Featured.php b/classes/Model/Featured.php index f0e620a8de..46050240b2 100644 --- a/classes/Model/Featured.php +++ b/classes/Model/Featured.php @@ -67,9 +67,9 @@ private function _get($key) $q = $this->db->query( "SELECT value FROM editorial WHERE item = :key", - array( + [ ':key' => $key, - ), + ], )->first(); if ($q) { @@ -89,25 +89,25 @@ private function _set($key, $value) } $check_q = $this->db->query( "SELECT value FROM editorial WHERE item = :key", - array( + [ ':key' => $key, - ), + ], ); if ($check_q->rows()) { $set_q = $this->db->query( "UPDATE editorial set value = :value WHERE item = :key", - array( + [ ':key' => $key, ':value' => $value, - ), + ], ); } else { $set_q = $this->db->query( "INSERT INTO editorial (item, value ) VALUES (:key, :value)", - array( + [ ':key' => $key, ':value' => $value, - ), + ], ); } diff --git a/classes/Party.php b/classes/Party.php index 7aadd793e9..20c32dc9ba 100644 --- a/classes/Party.php +++ b/classes/Party.php @@ -44,11 +44,11 @@ public function getCurrentMemberCount($house) AND house = :house AND entered_house <= :date AND left_house >= :date", - array( + [ ':party' => $this->name, ':house' => $house, ':date' => $date, - ), + ], )->first(); if ($member_count) { $num_members = $member_count['num_members']; @@ -66,7 +66,7 @@ public static function getParties() "SELECT DISTINCT party FROM member WHERE party <> ''", ); - $parties = array(); + $parties = []; foreach ($party_list as $row) { $party = $row['party']; if ( diff --git a/classes/PartyCohort.php b/classes/PartyCohort.php index aa44be4f09..5d555756ec 100644 --- a/classes/PartyCohort.php +++ b/classes/PartyCohort.php @@ -30,7 +30,7 @@ public function __construct($person_id, $party) public function getAllPolicyPositions($policies) { - $positions = array(); + $positions = []; $party = $this->party; if ($party == 'Independent') { @@ -60,10 +60,10 @@ public function policy_position($policy_id) party = :party AND house = 1 AND policy_id = :policy_id", - array( + [ ':party' => $this->hash, ':policy_id' => $policy_id, - ), + ], )->first(); if ($position) { diff --git a/classes/People.php b/classes/People.php index af6ba93986..83c5604bab 100644 --- a/classes/People.php +++ b/classes/People.php @@ -34,7 +34,7 @@ protected function getRegionalReps($user) return $user->getRegionalReps($this->reg_cons_type, $this->house); } - public function getData($args = array()) + public function getData($args = []) { $data = $this->_get_data_by_group($args); @@ -46,7 +46,7 @@ public function getData($args = array()) $data['mp_data'] = $user->getRep($this->cons_type, $this->house); $data['data'] = $this->addImagesToData($data['data']); $data['urls'] = $this->addUrlsToData(); - $data['order'] = isset($args['order']) ? $args['order'] : 'l'; + $data['order'] = $args['order'] ?? 'l'; $data['rep_plural'] = $this->rep_plural; $data['rep_name'] = $this->rep_name; $data['type'] = $this->type; @@ -59,7 +59,7 @@ public function getData($args = array()) public function getArgs() { - $args = array(); + $args = []; if (get_http_var('f') == 'csv') { $args['f'] = 'csv'; @@ -80,10 +80,10 @@ public function getArgs() } $order = get_http_var('o'); - $orders = array( + $orders = [ 'n' => 'name', 'f' => 'given_name', 'l' => 'family_name', 'c' => 'constituency', 'p' => 'party', - ); + ]; if (array_key_exists($order, $orders)) { $args['order'] = $orders[$order]; } @@ -106,18 +106,18 @@ public function setMetaData($args) protected function getCSVHeaders() { - return array(gettext('Person ID'), gettext('Name'), gettext('Party'), gettext('Constituency'), gettext('URI')); + return [gettext('Person ID'), gettext('Name'), gettext('Party'), gettext('Constituency'), gettext('URI')]; } protected function getCSVRow($details) { - return array( + return [ $details['person_id'], $details['name'], $details['party'], $details['constituency'], 'https://www.theyworkforyou.com/mp/' . $details['url'], - ); + ]; } public function sendAsCSV($data) @@ -139,9 +139,9 @@ public function sendAsCSV($data) private function addImagesToData($data) { - $new_data = array(); + $new_data = []; foreach ($data as $pid => $details) { - list($image, ) = Utility\Member::findMemberImage($pid, true, $this->subs_missing_image); + [$image, ] = Utility\Member::findMemberImage($pid, true, $this->subs_missing_image); $details['image'] = $image; $new_data[$pid] = $details; } @@ -153,28 +153,28 @@ private function addUrlsToData() { global $this_page; - $urls = array(); + $urls = []; $URL = new Url($this_page); $urls['plain'] = $URL->generate(); - $URL->insert(array( 'o' => 'n')); + $URL->insert([ 'o' => 'n']); $urls['by_name'] = $URL->generate(); - $URL->insert(array( 'o' => 'l')); + $URL->insert([ 'o' => 'l']); $urls['by_last'] = $URL->generate(); - $URL->insert(array( 'o' => 'f')); + $URL->insert([ 'o' => 'f']); $urls['by_first'] = $URL->generate(); - $URL->insert(array( 'o' => 'p')); + $URL->insert([ 'o' => 'p']); $urls['by_party'] = $URL->generate(); - $URL->insert(array( 'f' => 'csv')); - $URL->remove(array( 'o')); + $URL->insert([ 'f' => 'csv']); + $URL->remove([ 'o']); if ($date = get_http_var('date')) { - $URL->insert(array('date' => $date)); + $URL->insert(['date' => $date]); } $urls['by_csv'] = $URL->generate(); @@ -187,7 +187,7 @@ private function _get_data_by_group($args) $order = 'family_name'; $sqlorder = 'family_name, given_name'; - $params = array(); + $params = []; $query = 'SELECT distinct member.person_id, title, given_name, family_name, lordofname, constituency, party, left_reason '; $query .= 'FROM member JOIN person_names p ON p.person_id = member.person_id AND p.type = "name" '; if (isset($args['date'])) { @@ -217,7 +217,7 @@ private function _get_data_by_group($args) $q = $this->db->query($query . "ORDER BY $sqlorder", $params); - $data = array(); + $data = []; foreach ($q as $row) { $p_id = $row['person_id']; if (!isset($data[$p_id])) { @@ -225,7 +225,7 @@ private function _get_data_by_group($args) $constituency = $row['constituency'] ? gettext($row['constituency']) : ''; $party = $row['party'] ? gettext($row['party']) : ''; $url = make_member_url($name, $constituency, $this->house, $p_id); - $narray = array( + $narray = [ 'person_id' => $p_id, 'given_name' => $row['given_name'], 'family_name' => $row['family_name'], @@ -235,7 +235,7 @@ private function _get_data_by_group($args) 'constituency' => $constituency, 'party' => $party, 'left_reason' => $row['left_reason'], - ); + ]; $data[$p_id] = $narray; } } @@ -243,12 +243,12 @@ private function _get_data_by_group($args) uasort($data, 'by_peer_name'); } - $data = array( - 'info' => array( + $data = [ + 'info' => [ 'order' => $order, - ), + ], 'data' => $data, - ); + ]; return $data; diff --git a/classes/People/MPs.php b/classes/People/MPs.php index 0ddc2b17f1..6a922071e2 100644 --- a/classes/People/MPs.php +++ b/classes/People/MPs.php @@ -22,18 +22,18 @@ protected function getRegionalReps($user) protected function getCSVHeaders() { - return array('Person ID', 'First name', 'Last name', 'Party', 'Constituency', 'URI'); + return ['Person ID', 'First name', 'Last name', 'Party', 'Constituency', 'URI']; } protected function getCSVRow($details) { - return array( + return [ $details['person_id'], $details['given_name'], $details['family_name'], $details['party'], $details['constituency'], 'https://www.theyworkforyou.com/mp/' . $details['url'], - ); + ]; } } diff --git a/classes/People/Peers.php b/classes/People/Peers.php index 9ac1d72578..166f02fcb1 100644 --- a/classes/People/Peers.php +++ b/classes/People/Peers.php @@ -22,16 +22,16 @@ protected function getRegionalReps($user) protected function getCSVHeaders() { - return array('Person ID', 'Name', 'Party', 'URI'); + return ['Person ID', 'Name', 'Party', 'URI']; } protected function getCSVRow($details) { - return array( + return [ $details['person_id'], $details['name'], $details['party'], 'https://www.theyworkforyou.com/peer/' . $details['url'], - ); + ]; } } diff --git a/classes/Policies.php b/classes/Policies.php index ee62ea686a..f6400dd916 100644 --- a/classes/Policies.php +++ b/classes/Policies.php @@ -15,11 +15,11 @@ class Policies { - private $commons_only = array( + private $commons_only = [ 811, 826, 1053, - ); + ]; # policies where votes affected by covid voting restrictions protected $covid_affected = [1136, 6860]; @@ -80,9 +80,9 @@ public function __construct($policy_id = null) if ($policy_id) { $this->policy_id = $policy_id; - $this->policies = array( + $this->policies = [ $policy_id => $this->policies[$policy_id], - ); + ]; } } @@ -115,13 +115,13 @@ public function getSetDescriptions() */ public function getPoliciesData() { - $out = array(); + $out = []; foreach ($this->policies as $policy_id => $policy_text) { - $out[] = array( + $out[] = [ 'id' => $policy_id, 'text' => $policy_text, 'commons_only' => in_array($policy_id, $this->commons_only), - ); + ]; } return $out; } @@ -158,7 +158,7 @@ public function limitToSet($set) // Sanity check the set exists if (isset($this->sets[$set])) { - $out = array(); + $out = []; // Reassemble the new policies list based on the set. foreach ($this->sets[$set] as $set_policy) { if (isset($this->policies[$set_policy])) { @@ -186,7 +186,7 @@ public function limitToSet($set) public function limitToArray($policies) { - $out = array(); + $out = []; // Reassemble the new policies list based on the set. foreach ($policies as $policy) { if (isset($this->policies[$policy])) { @@ -205,10 +205,10 @@ public function getPolicyDetails($policyID) $q = $this->db->query( "SELECT policy_id, title, description, image, image_attrib, image_license, image_license_url, image_source FROM policies WHERE policy_id = :policy_id", - array(':policy_id' => $policyID), + [':policy_id' => $policyID], )->first(); - $props = array( + $props = [ 'policy_id' => $q['policy_id'], 'title' => $q['title'], // remove full stops from the end of descriptions. Some of them have them and @@ -219,7 +219,7 @@ public function getPolicyDetails($policyID) 'image_attribution' => '', 'image_source' => '', 'image_license_url' => '', - ); + ]; $image = $q['image']; diff --git a/classes/PolicyPositions.php b/classes/PolicyPositions.php index 856472b159..81c9a58ddf 100644 --- a/classes/PolicyPositions.php +++ b/classes/PolicyPositions.php @@ -40,9 +40,9 @@ class PolicyPositions * Array of positions held by the member. */ - public $positions = array(); + public $positions = []; - public $positionsById = array(); + public $positionsById = []; /** * 'Since' String @@ -62,14 +62,14 @@ class PolicyPositions * @param int $limit The number of policies to limit the list to. */ - public function __construct(Policies $policies, Member $member, $options = array()) + public function __construct(Policies $policies, Member $member, $options = []) { $this->policies = $policies; $this->member = $member; - $this->summaries = isset($options['summaries']) ? $options['summaries'] : array(); + $this->summaries = $options['summaries'] ?? []; $this->divisions = new \MySociety\TheyWorkForYou\Divisions($member); - $limit = isset($options['limit']) ? $options['limit'] : null; + $limit = $options['limit'] ?? null; // Do the actual getting of positions $this->getMemberPolicyPositions($limit); @@ -105,7 +105,7 @@ private function getMemberPolicyPositions($limit = null) // Set the current policy count to 0 $i = 0; - $this->positions = array(); + $this->positions = []; // Loop around all the policies. foreach ($policies as $policy) { @@ -125,7 +125,7 @@ private function getMemberPolicyPositions($limit = null) continue; } - $votes_summary = array_key_exists($policy['id'], $this->summaries) ? $this->summaries[$policy['id']] : array(); + $votes_summary = array_key_exists($policy['id'], $this->summaries) ? $this->summaries[$policy['id']] : []; $dream_info = $this->displayDreamComparison($policy['id'], $policy['text'], $votes_summary); // don't return votes where they haven't voted on a strong division @@ -137,15 +137,15 @@ private function getMemberPolicyPositions($limit = null) // Make sure the dream actually exists if (!empty($dream_info)) { $summary = $votes_summary ? $this->divisions->generateSummary($votes_summary) : ''; - $this->positions[] = array( + $this->positions[] = [ 'policy_id' => $policy['id'], 'policy' => $policy['text'], 'desc' => $dream_info['full_sentence'], 'has_strong' => $dream_info['has_strong'], 'position' => $dream_info['position'], 'summary' => $summary, - ); - $this->positionsById[$policy['id']] = array( + ]; + $this->positionsById[$policy['id']] = [ 'policy_id' => $policy['id'], 'policy' => $policy['text'], 'desc' => $dream_info['full_sentence'], @@ -153,7 +153,7 @@ private function getMemberPolicyPositions($limit = null) 'has_strong' => $dream_info['has_strong'], 'score' => $dream_info['score'], 'summary' => $summary, - ); + ]; $i++; } } @@ -185,7 +185,7 @@ private function getMemberPolicyPositions($limit = null) private function displayDreamComparison($dreamid, $policy_description, $votes_summary) { - $out = array(); + $out = []; $extra_info = $this->member->extra_info(); @@ -210,7 +210,7 @@ private function displayDreamComparison($dreamid, $policy_description, $votes_su $has_strong = 1; } $full_sentence = $consistency . ' ' . $policy_description; - $out = array( 'full_sentence' => $full_sentence, 'score' => $dmpscore, 'position' => $consistency, 'has_strong' => $has_strong ); + $out = [ 'full_sentence' => $full_sentence, 'score' => $dmpscore, 'position' => $consistency, 'has_strong' => $has_strong ]; } return $out; @@ -256,7 +256,7 @@ private function generateMoreLinksString() $extra_info = $this->member->extra_info; // Links to full record at Guardian and Public Whip - $record = array(); + $record = []; if (isset($extra_info['guardian_howtheyvoted'])) { $record[] = 'well-known issues (from the Guardian)'; diff --git a/classes/Redis.php b/classes/Redis.php index d75fc625b2..3753fb9493 100644 --- a/classes/Redis.php +++ b/classes/Redis.php @@ -7,7 +7,7 @@ class Redis extends \Predis\Client public function __construct() { if (REDIS_SENTINELS) { - $sentinels = array(); + $sentinels = []; $sentinel_port = REDIS_SENTINEL_PORT; foreach (explode(",", REDIS_SENTINELS) as $sentinel) { // Wrap IPv6 addresses in square brackets diff --git a/classes/Renderer.php b/classes/Renderer.php index 5ac29976b2..335d12c949 100644 --- a/classes/Renderer.php +++ b/classes/Renderer.php @@ -20,7 +20,7 @@ class Renderer * @param array $data An associative array of data to be made available to the template. */ - public static function output($template, $data = array(), $template_only = false) + public static function output($template, $data = [], $template_only = false) { global $page_errors; @@ -86,12 +86,12 @@ public static function output($template, $data = array(), $template_only = false private static function addCommonURLs($data) { - $urls = array(); + $urls = []; if (isset($data['urls'])) { $urls = $data['urls']; } - $common_urls = array('search', 'alert'); + $common_urls = ['search', 'alert']; foreach ($common_urls as $path) { if (!isset($urls[$path])) { diff --git a/classes/Renderer/Footer.php b/classes/Renderer/Footer.php index 726e79e849..9760cc43c5 100644 --- a/classes/Renderer/Footer.php +++ b/classes/Renderer/Footer.php @@ -13,10 +13,10 @@ class Footer { public $data; - private $about_links = array('help', 'about', 'linktous', 'news', 'privacy'); - private $assemblies_links = array('hansard', 'sp_home', 'wales_home', 'ni_home', 'london_home'); - private $international_links = array('australia', 'ireland', 'mzalendo'); - private $tech_links = array('code', 'api', 'data', 'devmailinglist', 'contact'); + private $about_links = ['help', 'about', 'linktous', 'news', 'privacy']; + private $assemblies_links = ['hansard', 'sp_home', 'wales_home', 'ni_home', 'london_home']; + private $international_links = ['australia', 'ireland', 'mzalendo']; + private $tech_links = ['code', 'api', 'data', 'devmailinglist', 'contact']; /* @@ -26,7 +26,7 @@ class Footer */ public function __construct() { - $this->data = array(); + $this->data = []; $this->data['about'] = $this->get_menu_links($this->about_links); $this->data['assemblies'] = $this->get_menu_links($this->assemblies_links); @@ -44,7 +44,7 @@ private function get_menu_links($pages) { global $DATA, $this_page; - $links = array(); + $links = []; foreach ($pages as $page) { @@ -66,19 +66,19 @@ private function get_menu_links($pages) //make the link if ($page == $this_page) { - $links[] = array( + $links[] = [ 'href' => '#', 'title' => '', 'classes' => '', 'text' => $title, - ); + ]; } else { - $links[] = array( + $links[] = [ 'href' => $url, 'title' => $tooltip, 'classes' => '', 'text' => $title, - ); + ]; } } diff --git a/classes/Renderer/Header.php b/classes/Renderer/Header.php index d7aa3d6da6..2231d9700b 100644 --- a/classes/Renderer/Header.php +++ b/classes/Renderer/Header.php @@ -18,7 +18,7 @@ class Header public function __construct() { - $this->data = array(); + $this->data = []; $this->get_page_url(); $this->get_page_title(); @@ -130,16 +130,16 @@ private function get_header_links() { global $this_page; - $this->data['header_links'] = array(); + $this->data['header_links'] = []; if ($this_page != 'overview') { $URL = new \MySociety\TheyWorkForYou\Url('overview'); - $this->data['header_links'][] = array( + $this->data['header_links'][] = [ 'rel' => 'start', 'title' => 'Home', 'href' => $URL->generate(), - ); + ]; } } @@ -160,11 +160,11 @@ private function generate_next_prev_link($nextprev, $linktype) $linktitle = format_date($nextprev[$linktype]['hdate'], SHORTDATEFORMAT); } - $link = array( + $link = [ 'rel' => $linktype, 'title' => $linktitle, 'href' => $nextprev[$linktype]['url'], - ); + ]; } return $link; @@ -178,7 +178,7 @@ private function get_next_prev_links() if ($nextprev) { // Four different kinds of back/forth links we might build. - $links = array("first", "prev", "up", "next", "last"); + $links = ["first", "prev", "up", "next", "last"]; foreach ($links as $type) { if ($link = $this->generate_next_prev_link($nextprev, $type)) { @@ -218,7 +218,7 @@ private function get_menu_highlights() } else { - $parents = array($parent); + $parents = [$parent]; $p = $parent; while ($p) { $p = $DATA->page_metadata($p, 'parent'); @@ -289,7 +289,7 @@ private function get_menu_highlights() // in the top bar if ($this_page == "alert") { if ($pid = get_http_var('pid')) { - $person = new \MySociety\TheyWorkForYou\Member(array('person_id' => $pid)); + $person = new \MySociety\TheyWorkForYou\Member(['person_id' => $pid]); $membership = $person->getMostRecentMembership(); $parliament = $membership['house']; if ($parliament == 'ni') { @@ -304,12 +304,12 @@ private function get_menu_highlights() } } - $this->nav_highlights = array( + $this->nav_highlights = [ 'top' => $top_highlight, 'bottom' => $bottom_highlight, 'top_selected' => $selected_top_link, 'section' => $section, - ); + ]; } private function get_top_and_bottom_links() @@ -319,17 +319,17 @@ private function get_top_and_bottom_links() // Page names mapping to those in metadata.php. // Links in the top menu, and the sublinks we see if // we're within that section. - $nav_items = array( - array('home'), - array('hansard', 'mps', 'peers', 'alldebatesfront', 'wranswmsfront', 'pbc_front', 'divisions_recent_commons', 'divisions_recent_lords', 'calendar_summary'), - array('sp_home', 'spoverview', 'msps', 'spdebatesfront', 'divisions_recent_sp'), #'spwransfront' - array('ni_home', 'nioverview', 'mlas'), - array('wales_home', 'seneddoverview', 'mss', 'wales_debates', 'divisions_recent_wales'), - array('london_home', 'lmqsfront', 'london-assembly-members'), - ); - - $this->data['assembly_nav_links'] = array(); - $this->data['section_nav_links'] = array(); + $nav_items = [ + ['home'], + ['hansard', 'mps', 'peers', 'alldebatesfront', 'wranswmsfront', 'pbc_front', 'divisions_recent_commons', 'divisions_recent_lords', 'calendar_summary'], + ['sp_home', 'spoverview', 'msps', 'spdebatesfront', 'divisions_recent_sp'], #'spwransfront' + ['ni_home', 'nioverview', 'mlas'], + ['wales_home', 'seneddoverview', 'mss', 'wales_debates', 'divisions_recent_wales'], + ['london_home', 'lmqsfront', 'london-assembly-members'], + ]; + + $this->data['assembly_nav_links'] = []; + $this->data['section_nav_links'] = []; //get the top and bottom links foreach ($nav_items as $bottompages) { @@ -359,12 +359,12 @@ private function get_top_and_bottom_links() $url = "//" . DOMAIN . $url; } - $top_link = array( + $top_link = [ 'href' => $url, 'title' => $title, 'classes' => $class, 'text' => $text, - ); + ]; if ($toppage != "london_home") { array_push($this->data['assembly_nav_links'], $top_link); } @@ -379,12 +379,12 @@ private function get_top_and_bottom_links() // Where we're linking to. $URL = new \MySociety\TheyWorkForYou\Url($bottompage); $class = $bottompage == $this->nav_highlights['bottom'] ? 'on' : ''; - $this->data['section_nav_links'][] = array( + $this->data['section_nav_links'][] = [ 'href' => $URL->generate(), 'title' => $title, 'classes' => $class, 'text' => $text, - ); + ]; } } } diff --git a/classes/Renderer/Markdown.php b/classes/Renderer/Markdown.php index 1ac158de38..8a9eaba76a 100644 --- a/classes/Renderer/Markdown.php +++ b/classes/Renderer/Markdown.php @@ -54,12 +54,12 @@ public function markdown_document($this_page, $show_menu = true) $html = str_replace('{{ donate_box }}', render_php('donate/_stripe_donate'), $html); } - \MySociety\TheyWorkForYou\Renderer::output('static/markdown_template', array( + \MySociety\TheyWorkForYou\Renderer::output('static/markdown_template', [ 'html' => $html, 'this_page' => $this_page, 'page_title' => $title, 'show_menu' => $show_menu, - )); + ]); } } diff --git a/classes/Renderer/User.php b/classes/Renderer/User.php index fc063d3f6b..06cc758eba 100644 --- a/classes/Renderer/User.php +++ b/classes/Renderer/User.php @@ -22,13 +22,13 @@ public function __construct() $this->user = $THEUSER; $this->pagedata = $DATA; $this->page = $this_page; - $this->data = array(); + $this->data = []; $this->setupNavLinks(); } private function setupNavLinks() { - $this->data['user_nav_links'] = array(); + $this->data['user_nav_links'] = []; // We may want to send the user back to this current page after they've // joined, logged out or logged in. So we put the URL in $returl. @@ -58,12 +58,12 @@ private function AddLangSwitcher() $href = "//cy." . DOMAIN . $href; } } - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $href, 'classes' => '', 'title' => '', 'text' => $text, - ); + ]; } } @@ -86,7 +86,7 @@ private function addLoggedInLinks() $LOGOUTURL = new \MySociety\TheyWorkForYou\Url('userlogout'); if ($this->page != 'userlogout') { - $LOGOUTURL->insert(array("ret" => $this->returl)); + $LOGOUTURL->insert(["ret" => $this->returl]); $logoutclass = ''; } else { $logoutclass = 'on'; @@ -96,19 +96,19 @@ private function addLoggedInLinks() $this->addRepLinks(); - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $EDITURL->generate(), 'title' => $edittitle, 'classes' => $editclass, 'text' => _htmlentities($username), - ); + ]; - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $LOGOUTURL->generate(), 'title' => $logouttitle, 'classes' => $logoutclass, 'text' => $logouttext, - ); + ]; $this->addContactLink(); $this->addDonateLink(); @@ -128,7 +128,7 @@ private function addLoggedOutLinks() // We don't do this on the logout page, because then the user // will return straight to the logout page and be logged out // immediately! - $JOINURL->insert(array("ret" => $this->returl)); + $JOINURL->insert(["ret" => $this->returl]); } $joinclass = ''; } else { @@ -150,26 +150,26 @@ private function addLoggedOutLinks() // immediately! // And it's also silly if we're sent back to Change Password. // And the join page. - $LOGINURL->insert(array("ret" => $this->returl)); + $LOGINURL->insert(["ret" => $this->returl]); } $loginclass = ''; } else { $loginclass = 'on'; } - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $LOGINURL->generate(), 'title' => $logintitle, 'classes' => $loginclass, 'text' => $logintext, - ); + ]; - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $JOINURL->generate(), 'title' => $jointitle, 'classes' => $joinclass, 'text' => $jointext, - ); + ]; $this->addRepLinks(); $this->addContactLink(); @@ -183,7 +183,7 @@ private function addRepLinks() if ($this->user->postcode_is_set()) { $areas = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($this->user->postcode()); - $items = array('yourmp'); + $items = ['yourmp']; if (isset($areas['SPC'])) { $items[] = 'yourmsp'; } elseif (isset($areas['NIE'])) { @@ -196,12 +196,12 @@ private function addRepLinks() $menudata = $this->pagedata->page_metadata($item, 'menu'); $logintext = $menudata['text']; $URL = new \MySociety\TheyWorkForYou\Url($item); - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $URL->generate(), 'title' => '', 'classes' => '', 'text' => $logintext, - ); + ]; } } @@ -213,12 +213,12 @@ private function addContactLink() $text = $menudata['text']; $title = $menudata['title']; $url = new \MySociety\TheyWorkForYou\Url('contact'); - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $url->generate(), 'title' => $title, 'classes' => '', 'text' => $text, - ); + ]; } private function addDonateLink() @@ -227,12 +227,12 @@ private function addDonateLink() $text = $menudata['text']; $title = $menudata['title']; $url = new \MySociety\TheyWorkForYou\Url('donate'); - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $url->generate(), 'title' => $title, 'classes' => 'donate-button', 'text' => $text, - ); + ]; } } diff --git a/classes/SPHomepage.php b/classes/SPHomepage.php index 0a66a63b22..d8568639b0 100644 --- a/classes/SPHomepage.php +++ b/classes/SPHomepage.php @@ -8,23 +8,23 @@ class SPHomepage extends Homepage protected $cons_type = 'SPC'; protected $mp_url = 'yourmsp'; protected $page = 'spoverview'; - protected $houses = array(7); + protected $houses = [7]; - protected $recent_types = array( - 'SPLIST' => array('recent_debates', 'spdebatesfront', 'Scottish parliament debates'), - 'SPWRANSLIST' => array('recent_wrans', 'spwransfront', 'Written answers'), - ); + protected $recent_types = [ + 'SPLIST' => ['recent_debates', 'spdebatesfront', 'Scottish parliament debates'], + 'SPWRANSLIST' => ['recent_wrans', 'spwransfront', 'Written answers'], + ]; protected function getEditorialContent() { $debatelist = new \SPLIST(); - $item = $debatelist->display('recent_debates', array('days' => 7, 'num' => 1), 'none'); + $item = $debatelist->display('recent_debates', ['days' => 7, 'num' => 1], 'none'); $item = $item['data'][0]; $more_url = new Url('spdebatesfront'); $item['more_url'] = $more_url->generate(); $item['desc'] = 'Scottish Parliament debate'; - $item['related'] = array(); + $item['related'] = []; $item['featured'] = false; return $item; @@ -32,7 +32,7 @@ protected function getEditorialContent() protected function getURLs() { - $urls = array(); + $urls = []; $regional = new Url('msp'); $urls['regional'] = $regional->generate(); @@ -50,7 +50,7 @@ protected function getRegionalList() { global $THEUSER; - $mreg = array(); + $mreg = []; if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) { return Member::getRegionalList($THEUSER->postcode, 4, 'SPE'); diff --git a/classes/Search.php b/classes/Search.php index 81ed5977bd..3d7594edcd 100644 --- a/classes/Search.php +++ b/classes/Search.php @@ -17,7 +17,7 @@ public function __construct() public function display() { - $data = array(); + $data = []; $argparser = new Search\ParseArgs(); $this->searchstring = $argparser->construct_search_string(); $this->searchkeyword = $argparser->searchkeyword; @@ -51,7 +51,7 @@ public function display() $data['person_id'] = $argparser->person_id; if ($argparser->person_id) { - $MEMBER = new \MEMBER(array('person_id' => $argparser->person_id)); + $MEMBER = new \MEMBER(['person_id' => $argparser->person_id]); $data['person_name'] = $MEMBER->full_name(); } @@ -137,16 +137,16 @@ private function prettify_search_section($section) private function get_urls() { global $this_page; - $urls = array(); + $urls = []; $url = new Url($this_page); - $url->insert(array('o' => 'r')); + $url->insert(['o' => 'r']); $urls['relevance'] = $url->generate(); - $url->insert(array('o' => 'o')); + $url->insert(['o' => 'o']); $urls['oldest'] = $url->generate(); - $url->insert(array('o' => 'd')); + $url->insert(['o' => 'd']); $urls['newest'] = $url->generate(); - $url->insert(array('o' => 'p')); + $url->insert(['o' => 'p']); $urls['by-person'] = $url->generate(); return $urls; @@ -157,7 +157,7 @@ private function get_form_params($data) $data['search_keyword'] = $this->searchkeyword; $is_adv = false; - foreach (array('to', 'from', 'person', 'section', 'column', 'phrase', 'exclude' ) as $var) { + foreach (['to', 'from', 'person', 'section', 'column', 'phrase', 'exclude' ] as $var) { $key = "search_$var"; $data[$key] = get_http_var($var); if ($data[$key]) { @@ -181,7 +181,7 @@ private function set_wtt_options($data) if ($wtt == 2 && $pid = get_http_var('pid')) { $data['pid'] = null; try { - $lord = new Member(array('person_id' => $pid, 'house' => 2)); + $lord = new Member(['person_id' => $pid, 'house' => 2]); } catch (MemberException $e) { return $data; } @@ -206,20 +206,20 @@ protected function get_search_url($params = true) if (preg_match_all('#speaker:(\d+)#', $value, $m) == 1) { $person_id = $m[1][0]; $value = str_replace('speaker:' . $person_id, '', $value); - $url->insert(array('pid' => $person_id)); + $url->insert(['pid' => $person_id]); } - $url->insert(array('q' => $value)); + $url->insert(['q' => $value]); } if ($params) { if (get_http_var('house')) { - $url->insert(array('house' => get_http_var('house'))); + $url->insert(['house' => get_http_var('house')]); } if (get_http_var('wtt')) { - $url->insert(array('wtt' => get_http_var('wtt'))); + $url->insert(['wtt' => get_http_var('wtt')]); } } else { - $url->remove(array('o', 'house')); + $url->remove(['o', 'house']); } return $url; diff --git a/classes/Search/Normal.php b/classes/Search/Normal.php index 7425e6fc01..d2455b0da0 100644 --- a/classes/Search/Normal.php +++ b/classes/Search/Normal.php @@ -14,13 +14,13 @@ private function get_sort_args() } $o = get_http_var('o'); - $args = array( + $args = [ 's' => $this->searchstring, 'p' => $pagenum, 'num' => get_http_var('num'), 'pop' => get_http_var('pop'), 'o' => ($o == 'd' || $o == 'r' || $o == 'o') ? $o : 'd', - ); + ]; return $args; } @@ -31,14 +31,14 @@ private function get_first_page_data($args) $cons = null; $glossary = null; - $mp_types = array(); + $mp_types = []; if ($args['p'] == 1 && $args['s'] && !preg_match('#[a-z]+:[a-z0-9]+#', $args['s'])) { $members = $this->find_members(); - list($cons, $mp_types) = $this->find_constituency($args); + [$cons, $mp_types] = $this->find_constituency($args); $glossary = $this->find_glossary_items($args); } - return array($members, $cons, $mp_types, $glossary); + return [$members, $cons, $mp_types, $glossary]; } public function search($searchstring) @@ -65,16 +65,16 @@ public function search($searchstring) $sort_order = 'relevance'; } - list($members, $cons, $mp_types, $glossary) = $this->get_first_page_data($args); + [$members, $cons, $mp_types, $glossary] = $this->get_first_page_data($args); if (!defined('FRONT_END_SEARCH') || !FRONT_END_SEARCH) { - return array( + return [ 'error' => 'Apologies, search has been turned off currently for performance reasons.', - ); + ]; } if (!$SEARCHENGINE->valid) { - return array('error' => $SEARCHENGINE->error); + return ['error' => $SEARCHENGINE->error]; } else { $LIST = new \HANSARDLIST(); $data = $LIST->display('search', $args, 'none'); @@ -98,24 +98,24 @@ private function find_constituency($args) return false; } - list($constituencies, ) = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($searchterm); + [$constituencies, ] = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($searchterm); $constituency = ""; if (count($constituencies) == 1) { $constituency = $constituencies[0]; } - $cons = array(); - $mp_types = array( + $cons = []; + $mp_types = [ 'mp' => 0, 'former' => 0, - ); + ]; if ($constituency != '') { try { // Got a match, display.... - $MEMBER = new \MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => 1)); + $MEMBER = new \MySociety\TheyWorkForYou\Member(['constituency' => $constituency, 'house' => 1]); $cons[] = $MEMBER; if ($MEMBER->current_member(1)) { $mp_types['mp']++; @@ -123,12 +123,12 @@ private function find_constituency($args) $mp_types['former']++; } } catch (\MySociety\TheyWorkForYou\MemberException $e) { - $cons = array(); + $cons = []; } } elseif (count($constituencies)) { foreach ($constituencies as $constituency) { try { - $MEMBER = new \MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => 1)); + $MEMBER = new \MySociety\TheyWorkForYou\Member(['constituency' => $constituency, 'house' => 1]); $cons[] = $MEMBER; if ($MEMBER->current_member(1)) { $mp_types['mp']++; @@ -141,14 +141,14 @@ private function find_constituency($args) } } - return array($cons, $mp_types); + return [$cons, $mp_types]; } private function find_members() { $searchstring = trim(preg_replace('#-?[a-z]+:[a-z0-9]+#', '', $this->searchstring)); if (!$searchstring) { - return array(); + return []; } $members = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookup($searchstring); @@ -156,7 +156,7 @@ private function find_members() $db = new \ParlDB(); $q = $db->query( "SELECT person FROM moffice WHERE position LIKE :pos ORDER BY from_date DESC, moffice_id", - array('pos' => "%$searchstring%"), + ['pos' => "%$searchstring%"], ); foreach ($q as $row) { $members[] = $row['person']; @@ -166,7 +166,7 @@ private function find_members() $members = array_unique($members); foreach ($members as $i => $pid) { - $member = new \MySociety\TheyWorkForYou\Member(array('person_id' => $pid)); + $member = new \MySociety\TheyWorkForYou\Member(['person_id' => $pid]); $members[$i] = $member; } return $members; @@ -175,18 +175,18 @@ private function find_members() private function find_glossary_items($args) { $GLOSSARY = new \GLOSSARY($args); - $items = array(); + $items = []; if (isset($GLOSSARY->num_search_matches) && $GLOSSARY->num_search_matches >= 1) { $URL = new \MySociety\TheyWorkForYou\Url('glossary'); - $URL->insert(array('gl' => "")); + $URL->insert(['gl' => ""]); foreach ($GLOSSARY->search_matches as $glossary_id => $term) { - $URL->update(array("gl" => $glossary_id)); - $items[] = array( + $URL->update(["gl" => $glossary_id]); + $items[] = [ 'url' => $URL->generate(), 'term' => $term['title'], 'body' => $term['body'], - ); + ]; } } return $items; @@ -194,22 +194,22 @@ private function find_glossary_items($args) private function generate_pagination_links($data, $url, $first, $last) { - $links = array(); + $links = []; for ($n = $first; $n <= $last; $n++) { if ($n > 1) { - $url->insert(array('p' => $n)); + $url->insert(['p' => $n]); } else { // No page number for the first page. - $url->remove(array('p')); + $url->remove(['p']); } - $link = array( + $link = [ 'url' => $url->generate(), 'page' => $n, 'current' => ($n == $data['page']), - ); + ]; $links[] = $link; } @@ -222,7 +222,7 @@ private function generate_pagination($data) $total_results = $data['total_results']; $results_per_page = $data['results_per_page']; $page = $data['page']; - $pagelinks = array(); + $pagelinks = []; $URL = $this->get_search_url($data); @@ -255,25 +255,25 @@ private function generate_pagination($data) if ($page != 1) { $prev_page = $page - 1; - $URL->insert(array( 'p' => $prev_page )); - $pagelinks['prev'] = array( + $URL->insert([ 'p' => $prev_page ]); + $pagelinks['prev'] = [ 'url' => $URL->generate(), - ); - $URL->insert(array( 'p' => 1 )); - $pagelinks['firstpage'] = array( + ]; + $URL->insert([ 'p' => 1 ]); + $pagelinks['firstpage'] = [ 'url' => $URL->generate(), - ); + ]; } if ($page != $numpages) { $next_page = $page + 1; - $URL->insert(array( 'p' => $next_page )); - $pagelinks['next'] = array( + $URL->insert([ 'p' => $next_page ]); + $pagelinks['next'] = [ 'url' => $URL->generate(), - ); - $URL->insert(array( 'p' => $numpages )); - $pagelinks['lastpage'] = array( + ]; + $URL->insert([ 'p' => $numpages ]); + $pagelinks['lastpage'] = [ 'url' => $URL->generate(), - ); + ]; } } @@ -284,7 +284,7 @@ private function get_sidebar_links() { global $DATA, $SEARCHENGINE, $this_page; - $links = array(); + $links = []; $links['rss'] = $DATA->page_metadata($this_page, 'rss'); if ($SEARCHENGINE) { diff --git a/classes/SectionView/DebatesView.php b/classes/SectionView/DebatesView.php index cf30e514bf..09c923aa7a 100644 --- a/classes/SectionView/DebatesView.php +++ b/classes/SectionView/DebatesView.php @@ -16,38 +16,38 @@ protected function display_front() $this_page = "alldebatesfront"; $DEBATELIST = new \DEBATELIST(); - $debates = array(); - $debates['data'] = $DEBATELIST->display('biggest_debates', array('days' => 7, 'num' => 10), 'none'); - $args = array( 'months' => 1 ); + $debates = []; + $debates['data'] = $DEBATELIST->display('biggest_debates', ['days' => 7, 'num' => 10], 'none'); + $args = [ 'months' => 1 ]; $debates['calendar'] = $DEBATELIST->display('calendar', $args, 'none'); $debates['rssurl'] = $DATA->page_metadata($this_page, 'rss'); $this_page = "whallfront"; - $whall = array(); + $whall = []; $WHALLLIST = new \WHALLLIST(); - $whall['data'] = $WHALLLIST->display('biggest_debates', array('days' => 7, 'num' => 10), 'none'); - $args = array( 'months' => 1 ); + $whall['data'] = $WHALLLIST->display('biggest_debates', ['days' => 7, 'num' => 10], 'none'); + $args = [ 'months' => 1 ]; $whall['calendar'] = $WHALLLIST->display('calendar', $args, 'none'); $whall['rssurl'] = $DATA->page_metadata($this_page, 'rss'); $this_page = "lordsdebatesfront"; - $lords = array(); + $lords = []; $LORDSDEBATELIST = new \LORDSDEBATELIST(); - $lords['data'] = $LORDSDEBATELIST->display('biggest_debates', array('days' => 7, 'num' => 10), 'none'); - $args = array( 'months' => 1 ); + $lords['data'] = $LORDSDEBATELIST->display('biggest_debates', ['days' => 7, 'num' => 10], 'none'); + $args = [ 'months' => 1 ]; $lords['calendar'] = $LORDSDEBATELIST->display('calendar', $args, 'none'); $lords['rssurl'] = $DATA->page_metadata($this_page, 'rss'); - $data = array( + $data = [ 'debates' => $debates, 'lords' => $lords, 'whall' => $whall, - ); + ]; $data['template'] = 'section/index'; $this_page = "alldebatesfront"; @@ -57,10 +57,10 @@ protected function display_front() protected function getSearchSections() { - return array( - array( 'section' => 'debates', 'title' => 'House of Commons' ), - array( 'section' => 'lords', 'title' => 'House of Lords' ), - array( 'section' => 'whall', 'title' => 'Westminster Hall' ), - ); + return [ + [ 'section' => 'debates', 'title' => 'House of Commons' ], + [ 'section' => 'lords', 'title' => 'House of Lords' ], + [ 'section' => 'whall', 'title' => 'Westminster Hall' ], + ]; } } diff --git a/classes/SectionView/LondonView.php b/classes/SectionView/LondonView.php index 27e610cebe..4fda46bdb6 100644 --- a/classes/SectionView/LondonView.php +++ b/classes/SectionView/LondonView.php @@ -9,12 +9,12 @@ class LondonView extends SectionView protected function front_content() { - return $this->list->display('recent_wrans', array('days' => 30, 'num' => 20), 'none'); + return $this->list->display('recent_wrans', ['days' => 30, 'num' => 20], 'none'); } protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('lmqs'); $urls['lmqsday'] = $day; $urls['day'] = $day; @@ -23,8 +23,8 @@ protected function getViewUrls() protected function getSearchSections() { - return array( - array( 'section' => 'lmqs', 'title' => 'Mayoral Questions' ), - ); + return [ + [ 'section' => 'lmqs', 'title' => 'Mayoral Questions' ], + ]; } } diff --git a/classes/SectionView/LordsView.php b/classes/SectionView/LordsView.php index d27b9e4443..19c905821a 100644 --- a/classes/SectionView/LordsView.php +++ b/classes/SectionView/LordsView.php @@ -9,6 +9,6 @@ class LordsView extends SectionView protected function front_content() { - return $this->list->display('biggest_debates', array('days' => 7, 'num' => 20), 'none'); + return $this->list->display('biggest_debates', ['days' => 7, 'num' => 20], 'none'); } } diff --git a/classes/SectionView/NiView.php b/classes/SectionView/NiView.php index bea7dec137..29ca4f2ddf 100644 --- a/classes/SectionView/NiView.php +++ b/classes/SectionView/NiView.php @@ -19,12 +19,12 @@ protected function display_front() protected function front_content() { - return $this->list->display('biggest_debates', array('days' => 30, 'num' => 20), 'none'); + return $this->list->display('biggest_debates', ['days' => 30, 'num' => 20], 'none'); } protected function getURLs($data) { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('nidebates'); $urls['niday'] = $day; @@ -36,9 +36,9 @@ protected function getURLs($data) protected function getSearchSections() { - return array( - array( 'section' => 'ni' ), - ); + return [ + [ 'section' => 'ni' ], + ]; } protected function display_front_ni() @@ -46,7 +46,7 @@ protected function display_front_ni() global $this_page; $this_page = "nioverview"; - $data = array(); + $data = []; $data['popular_searches'] = null; @@ -55,9 +55,9 @@ protected function display_front_ni() $DEBATELIST = new \NILIST(); - $debates = $DEBATELIST->display('recent_debates', array('days' => 30, 'num' => 6), 'none'); + $debates = $DEBATELIST->display('recent_debates', ['days' => 30, 'num' => 6], 'none'); $MOREURL = new \MySociety\TheyWorkForYou\Url('nidebatesfront'); - $MOREURL->insert(array( 'more' => 1 )); + $MOREURL->insert([ 'more' => 1 ]); // this makes sure that we don't repeat this debate in the list below $random_debate = null; @@ -65,7 +65,7 @@ protected function display_front_ni() $random_debate = $debates['data'][0]; } - $recent = array(); + $recent = []; if (isset($debates['data']) && count($debates['data'])) { // at the start of a session there may be less than 6 // debates @@ -81,17 +81,17 @@ protected function display_front_ni() } } - $featured = array(); + $featured = []; if ($random_debate) { $featured = $random_debate; $featured['more_url'] = $MOREURL->generate(); $featured['desc'] = 'Northern Ireland Assembly debate'; - $featured['related'] = array(); + $featured['related'] = []; $featured['featured'] = false; } $data['featured'] = $featured; - $data['debates'] = array( 'recent' => $recent); + $data['debates'] = [ 'recent' => $recent]; $data['regional'] = $this->getMLAList(); $data['template'] = 'ni/index'; @@ -103,7 +103,7 @@ protected function getMLAList() { global $THEUSER; - $mreg = array(); + $mreg = []; if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) { return \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 3, 'NIE'); } diff --git a/classes/SectionView/PbcView.php b/classes/SectionView/PbcView.php index 3d26c0fcc2..7d8ccf9cda 100644 --- a/classes/SectionView/PbcView.php +++ b/classes/SectionView/PbcView.php @@ -37,10 +37,10 @@ protected function public_bill_committees() $bill_id = null; if ($this->session && $this->bill) { $q = $this->list->db->query('select id,standingprefix from bills where title = :bill - and session = :session', array( + and session = :session', [ ':bill' => $this->bill, ':session' => $this->session, - ))->first(); + ])->first(); if ($q) { $bill_id = $q['id']; $standingprefix = $q['standingprefix']; @@ -48,18 +48,18 @@ protected function public_bill_committees() } if ($bill_id && $id) { - return $this->display_section_or_speech(array( + return $this->display_section_or_speech([ 'gid' => $standingprefix . $id, - )); + ]); } elseif ($bill_id) { # Display the page for a particular bill $this_page = 'pbc_bill'; - $args = array( + $args = [ 'id' => $bill_id, 'title' => $this->bill, 'session' => $this->session, - ); - $data = array(); + ]; + $data = []; $data['content'] = $this->list->display('bill', $args, 'none'); $data['session'] = $this->session; $data['template'] = 'section/pbc_bill'; @@ -73,10 +73,10 @@ protected function public_bill_committees() # Display the bills for a particular session $this_page = 'pbc_session'; $DATA->set_page_metadata($this_page, 'title', "Session $this->session"); - $args = array( + $args = [ 'session' => $this->session, - ); - $data = array(); + ]; + $data = []; $data['rows'] = $this->list->display('session', $args, 'none'); $data['template'] = 'section/pbc_session'; $data['session'] = $this->session; @@ -88,7 +88,7 @@ protected function public_bill_committees() protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('pbc_front'); $urls['pbcday'] = $day; return $urls; @@ -96,14 +96,14 @@ protected function getViewUrls() protected function getSearchSections() { - return array( - array( 'section' => 'pbc' ), - ); + return [ + [ 'section' => 'pbc' ], + ]; } protected function front_content() { - return $this->list->display('recent_pbc_debates', array( 'num' => 50 ), 'none'); + return $this->list->display('recent_pbc_debates', [ 'num' => 50 ], 'none'); } protected function display_front() @@ -111,10 +111,10 @@ protected function display_front() global $DATA, $this_page; $this_page = 'pbc_front'; - $data = array(); + $data = []; $data['template'] = $this->index_template; - $content = array(); + $content = []; $content['data'] = $this->front_content(); $content['rssurl'] = $DATA->page_metadata($this_page, 'rss'); diff --git a/classes/SectionView/SectionView.php b/classes/SectionView/SectionView.php index d38de68f43..314a56e849 100644 --- a/classes/SectionView/SectionView.php +++ b/classes/SectionView/SectionView.php @@ -25,7 +25,7 @@ public function __construct() $this->list = new $this->class(); } - list($country, $location, $assembly) = $this->getCountryDetails(); + [$country, $location, $assembly] = $this->getCountryDetails(); $this->location = $location; $this->assembly = $assembly; } @@ -98,7 +98,7 @@ protected function getURLs($data) { global $DATA, $this_page; - $urls = array(); + $urls = []; $urls = array_merge($urls, $this->getViewUrls()); @@ -112,7 +112,7 @@ protected function getURLs($data) protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('debates'); $urls['debatesday'] = $day; $urls['day'] = $day; @@ -125,7 +125,7 @@ protected function getViewUrls() protected function getSearchSections() { - return array(); + return []; } protected function getRecessMajor() @@ -150,7 +150,7 @@ protected function display_year($year) $DATA->set_page_metadata($this_page, 'title', $year); } - $args = array( 'year' => $year ); + $args = [ 'year' => $year ]; $data = $this->list->display('calendar', $args, 'none'); return $data; } @@ -159,18 +159,18 @@ protected function display_column($date, $column) { global $this_page; $this_page = $this->page_base; - $args = array( 'date' => $date, 'column' => $column ); + $args = [ 'date' => $date, 'column' => $column ]; $content = $this->list->display('column', $args, 'none'); - $data = array(); + $data = []; $data['column'] = $column; $URL = new \MySociety\TheyWorkForYou\Url($this->list->listpage); - $URL->insert(array('d' => $date)); + $URL->insert(['d' => $date]); $data['debate_day_link'] = $URL->generate(); $data['debate_day_human'] = format_date($date, LONGDATEFORMAT); $data['rows'] = $content; - $data['info'] = array('major' => $this->major, 'date' => $date); + $data['info'] = ['major' => $this->major, 'date' => $date]; $data['template'] = 'section/column'; return $data; @@ -180,10 +180,10 @@ protected function display_day($date) { global $this_page; $this_page = $this->page_base . 'day'; - $args = array( 'date' => get_http_var('d') ); + $args = [ 'date' => get_http_var('d') ]; $data = $this->list->display('date', $args, 'none'); - list($year, $month, $day) = explode('-', $date); - $args = array( 'year' => $year, 'month' => $month, 'day' => $day); + [$year, $month, $day] = explode('-', $date); + $args = [ 'year' => $year, 'month' => $month, 'day' => $day]; $calendar = $this->list->display('calendar', $args, 'none'); if (isset($calendar['years'])) { $data['calendar'] = $calendar['years']; @@ -191,16 +191,16 @@ protected function display_day($date) return $data; } - protected function display_section_or_speech($args = array()) + protected function display_section_or_speech($args = []) { global $DATA, $this_page, $THEUSER; # += as we *don't* want to override any already supplied argument - $args += array( + $args += [ 'gid' => get_http_var('id'), 's' => get_http_var('s'), // Search terms to be highlighted. 'member_id' => get_http_var('m'), // Member's speeches to be highlighted. - ); + ]; if (preg_match('/speaker:(\d+)/', get_http_var('s'), $mmm)) { $args['person_id'] = $mmm[1]; @@ -213,14 +213,14 @@ protected function display_section_or_speech($args = array()) if ($this->major == 6) { # Magically (as in I can't remember quite why), pbc_clause will # contain the new URL without any change... - $URL->remove(array('id')); + $URL->remove(['id']); } else { - $URL->insert(array('id' => $e->getMessage())); + $URL->insert(['id' => $e->getMessage()]); } # put the search term back in so highlighting works. # NB: as we don't see the # part of the URL we lose this :( if ($args['s'] !== '') { - $URL->insert(array('s' => $args['s'])); + $URL->insert(['s' => $args['s']]); } redirect($URL->generate('none'), 301); } @@ -233,11 +233,11 @@ protected function display_section_or_speech($args = array()) $args['epobject_id'] = $this->list->epobject_id(); $data['comments']['object'] = $COMMENTLIST; $data['comments']['args'] = $args; - $data['comments']['commentdata'] = array( + $data['comments']['commentdata'] = [ 'epobject_id' => $this->list->epobject_id(), 'gid' => get_http_var('id'), # wrans is LIST->gid? 'return_page' => $this_page, - ); + ]; } if (!isset($data['info'])) { @@ -248,9 +248,9 @@ protected function display_section_or_speech($args = array()) # Okay, let's set up highlighting and glossarisation - list($bodies, $speeches) = $this->highlightSpeeches($data); + [$bodies, $speeches] = $this->highlightSpeeches($data); - list($data, $first_speech, $subsection_title) = $this->annotateSpeeches($data, $bodies, $speeches); + [$data, $first_speech, $subsection_title] = $this->annotateSpeeches($data, $bodies, $speeches); $data = $this->setTitleAndAlertText($data, $subsection_title); @@ -260,8 +260,8 @@ protected function display_section_or_speech($args = array()) $data['debate_day_human'] = format_date($data['info']['date'], LONGDATEFORMAT); $URL = new \MySociety\TheyWorkForYou\Url($this->list->listpage); - $URL->insert(array('d' => $data['info']['date'])); - $URL->remove(array('id')); + $URL->insert(['d' => $data['info']['date']]); + $URL->remove(['id']); $data['debate_day_link'] = $URL->generate(); $data['nextprev'] = $DATA->page_metadata($this_page, 'nextprev'); @@ -338,7 +338,7 @@ private function highlightSpeeches($data) // and highlight search string words. $speeches = 0; - $bodies = array(); + $bodies = []; foreach ($data['rows'] as $row) { $htype = $row['htype']; if ($htype == 12 || $htype == 13 || $htype == 14) { @@ -372,7 +372,7 @@ private function highlightSpeeches($data) twfy_debug_timestamp('After glossarise'); } - return array($bodies, $speeches); + return [$bodies, $speeches]; } private function annotateSpeeches($data, $bodies, $speeches) @@ -437,81 +437,81 @@ private function annotateSpeeches($data, $bodies, $speeches) } } - return array($data, $first_speech, $subsection_title); + return [$data, $first_speech, $subsection_title]; } private function getCountryDetails() { - $details = array( - 1 => array( + $details = [ + 1 => [ 'country' => 'UK', 'assembly' => 'uk-commons', 'location' => '– in the House of Commons', - ), - 2 => array( + ], + 2 => [ 'country' => 'UK', 'assembly' => 'uk-commons', 'location' => '– in Westminster Hall', - ), - 3 => array( + ], + 3 => [ 'country' => 'UK', 'assembly' => 'uk-commons', 'location' => 'written question – answered', - ), - 4 => array( + ], + 4 => [ 'country' => 'UK', 'assembly' => 'uk-commons', 'location' => 'written statement – made', - ), - 5 => array( + ], + 5 => [ 'country' => 'NORTHERN IRELAND', 'assembly' => 'ni', 'location' => '– in the Northern Ireland Assembly', - ), - 6 => array( + ], + 6 => [ 'country' => 'UK', 'assembly' => 'uk-commons', 'location' => '– in a Public Bill Committee', - ), - 7 => array( + ], + 7 => [ 'country' => 'SCOTLAND', 'assembly' => 'scotland', 'location' => '– in the Scottish Parliament', - ), - 8 => array( + ], + 8 => [ 'country' => 'SCOTLAND', 'assembly' => 'scotland', 'location' => '– Scottish Parliament written question – answered', - ), - 9 => array( + ], + 9 => [ 'country' => 'LONDON', 'assembly' => 'london-assembly', 'location' => 'Questions to the Mayor of London – answered', - ), - 10 => array( + ], + 10 => [ 'country' => 'WALES', 'assembly' => 'senedd', 'location' => '– in the Senedd', - ), - 11 => array( + ], + 11 => [ 'country' => 'WALES', 'assembly' => 'senedd', 'location' => '– Senedd Cymru', - ), - 101 => array( + ], + 101 => [ 'country' => 'UK', 'assembly' => 'uk-lords', 'location' => '– in the House of Lords', - ), - ); + ], + ]; $detail = $details[$this->major]; - return array($detail['country'], $detail['location'], $detail['assembly']); + return [$detail['country'], $detail['location'], $detail['assembly']]; } private function majorToConsType() { - $major_to_cons_type = array( + $major_to_cons_type = [ 1 => 'WMC', 2 => 'WMC', 3 => 'WMC', @@ -523,7 +523,7 @@ private function majorToConsType() 10 => 'WAC', 11 => 'WAC', 101 => '', - ); + ]; return $major_to_cons_type[$this->major]; } @@ -532,16 +532,16 @@ protected function display_front() { global $DATA, $this_page; $this_page = $this->page_base . 'front'; - $data = array(); + $data = []; if ($this->index_template) { $data['template'] = $this->index_template; } $class = new $this->class(); - $content = array(); + $content = []; $content['data'] = $this->front_content(); - $content['calendar'] = $class->display('calendar', array('months' => 1), 'none'); + $content['calendar'] = $class->display('calendar', ['months' => 1], 'none'); if ($rssurl = $DATA->page_metadata($this_page, 'rss')) { $content['rssurl'] = $rssurl; @@ -609,13 +609,13 @@ public function generate_commentteaser($row) } } - return array( + return [ 'body' => prepare_comment_for_display($commentbody), 'username' => _htmlentities($comment['username']), 'linktext' => $linktext, 'commentsurl' => $row['commentsurl'], 'comment_id' => $comment['comment_id'], - ); + ]; } protected function get_question_mentions_html($row_data) @@ -625,7 +625,7 @@ protected function get_question_mentions_html($row_data) private function pageToSection() { - $sections = array( + $sections = [ 1 => 'debates', 2 => 'whall', 3 => 'wrans', @@ -638,7 +638,7 @@ private function pageToSection() 10 => 'senedd', 11 => 'senedd', 101 => 'lords', - ); + ]; return $sections[$this->major]; } diff --git a/classes/SectionView/SeneddView.php b/classes/SectionView/SeneddView.php index 1cb96fd718..f47c9683d2 100644 --- a/classes/SectionView/SeneddView.php +++ b/classes/SectionView/SeneddView.php @@ -29,12 +29,12 @@ protected function display_front() protected function front_content() { - return $this->list->display('biggest_debates', array('days' => 30, 'num' => 20), 'none'); + return $this->list->display('biggest_debates', ['days' => 30, 'num' => 20], 'none'); } protected function getURLs($data) { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('senedddebates'); $urls['seneddday'] = $day; @@ -45,9 +45,9 @@ protected function getURLs($data) protected function getSearchSections() { - return array( - array( 'section' => 'wales' ), - ); + return [ + [ 'section' => 'wales' ], + ]; } protected function display_front_senedd() @@ -55,7 +55,7 @@ protected function display_front_senedd() global $this_page; $this_page = "seneddoverview"; - $data = array(); + $data = []; $data['popular_searches'] = null; @@ -66,9 +66,9 @@ protected function display_front_senedd() $DEBATELIST = new $this->class(); - $debates = $DEBATELIST->display('recent_debates', array('days' => 30, 'num' => 6), 'none'); + $debates = $DEBATELIST->display('recent_debates', ['days' => 30, 'num' => 6], 'none'); $MOREURL = new \MySociety\TheyWorkForYou\Url('senedddebatesfront'); - $MOREURL->insert(array( 'more' => 1 )); + $MOREURL->insert([ 'more' => 1 ]); // this makes sure that we don't repeat this debate in the list below $random_debate = null; @@ -76,7 +76,7 @@ protected function display_front_senedd() $random_debate = $debates['data'][0]; } - $recent = array(); + $recent = []; if (isset($debates['data']) && count($debates['data'])) { // at the start of a session there may be less than 6 // debates @@ -92,17 +92,17 @@ protected function display_front_senedd() } } - $featured = array(); + $featured = []; if ($random_debate) { $featured = $random_debate; $featured['more_url'] = $MOREURL->generate(); $featured['desc'] = 'Senedd'; - $featured['related'] = array(); + $featured['related'] = []; $featured['featured'] = false; } $data['featured'] = $featured; - $data['debates'] = array( 'recent' => $recent); + $data['debates'] = [ 'recent' => $recent]; $data['regional'] = $this->getMSList(); $data['template'] = 'senedd/index'; @@ -114,7 +114,7 @@ protected function getMSList() { global $THEUSER; - $mreg = array(); + $mreg = []; if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) { return array_merge( \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 5, 'WAC'), diff --git a/classes/SectionView/SpView.php b/classes/SectionView/SpView.php index 06d08c4c32..0f44227040 100644 --- a/classes/SectionView/SpView.php +++ b/classes/SectionView/SpView.php @@ -9,7 +9,7 @@ class SpView extends SectionView protected function front_content() { - return $this->list->display('biggest_debates', array('days' => 7, 'num' => 20), 'none'); + return $this->list->display('biggest_debates', ['days' => 7, 'num' => 20], 'none'); } protected function get_question_mentions_html($row_data) @@ -19,7 +19,7 @@ protected function get_question_mentions_html($row_data) protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('spdebates'); $urls['spdebatesday'] = $day; $urls['day'] = $day; @@ -28,8 +28,8 @@ protected function getViewUrls() protected function getSearchSections() { - return array( - array( 'section' => 'sp' ), - ); + return [ + [ 'section' => 'sp' ], + ]; } } diff --git a/classes/SectionView/SpwransView.php b/classes/SectionView/SpwransView.php index 72545f078b..025e92a718 100644 --- a/classes/SectionView/SpwransView.php +++ b/classes/SectionView/SpwransView.php @@ -22,13 +22,13 @@ protected function display_front() { global $this_page, $DATA; $this_page = 'spwransfront'; - $data = array(); + $data = []; - $args = array( 'months' => 1 ); + $args = [ 'months' => 1 ]; $WRANSLIST = new \SPWRANSLIST(); - $wrans = array(); - $wrans['data'] = $WRANSLIST->display('recent_wrans', array('days' => 7, 'num' => 5), 'none'); + $wrans = []; + $wrans['data'] = $WRANSLIST->display('recent_wrans', ['days' => 7, 'num' => 5], 'none'); $wrans['calendar'] = $WRANSLIST->display('calendar', $args, 'none'); $data['content'] = $wrans; @@ -38,7 +38,7 @@ protected function display_front() protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('spwrans'); $urls['day'] = $day; $urls['spwransday'] = $day; @@ -47,9 +47,9 @@ protected function getViewUrls() protected function getSearchSections() { - return array( - array( 'section' => 'spwrans' ), - ); + return [ + [ 'section' => 'spwrans' ], + ]; } private function spwrans_redirect($spid) @@ -63,14 +63,14 @@ private function spwrans_redirect($spid) if (preg_match('/uk\.org\.publicwhip\/spwa\/(\d{4}-\d\d-\d\d\.(.*))/', $gid, $m)) { $URL = new \MySociety\TheyWorkForYou\Url('spwrans'); $URL->reset(); - $URL->insert(array('id' => $m[1])); + $URL->insert(['id' => $m[1]]); $fragment_identifier = '#g' . $m[2]; header('Location: ' . $URL->generate('none') . $fragment_identifier, true, 303); exit; } elseif (preg_match('/uk\.org\.publicwhip\/spor\/(\d{4}-\d\d-\d\d\.(.*))/', $gid, $m)) { $URL = new \MySociety\TheyWorkForYou\Url('spdebates'); $URL->reset(); - $URL->insert(array('id' => $m[1])); + $URL->insert(['id' => $m[1]]); $fragment_identifier = '#g' . $m[2]; header('Location: ' . $URL->generate('none') . $fragment_identifier, true, 303); exit; @@ -90,7 +90,7 @@ protected function get_question_mentions_html($row_data) $last_date = null; $first_difference_output = true; // Keep the references until after the history that's in a timeline: - $references = array(); + $references = []; foreach ($row_data as $row) { if(! $row["date"]) { // If this mention isn't associated with a date, the difference won't be interesting. @@ -129,7 +129,7 @@ protected function get_question_mentions_html($row_data) case 4: if(preg_match('/^uk.org.publicwhip\/spq\/(.*)$/', $row['gid'], $m)) { $URL = new \MySociety\TheyWorkForYou\Url("spwrans"); - $URL->insert(array('spid' => $m[1])); + $URL->insert(['spid' => $m[1]]); $relative_url = $URL->generate("none"); $inner = "Given a written answer on $date"; } @@ -140,7 +140,7 @@ protected function get_question_mentions_html($row_data) case 6: if(preg_match('/^uk.org.publicwhip\/spor\/(.*)$/', $row['mentioned_gid'], $m)) { $URL = new \MySociety\TheyWorkForYou\Url("spdebates"); - $URL->insert(array('id' => $m[1])); + $URL->insert(['id' => $m[1]]); $relative_url = $URL->generate("none"); $inner = "Asked in parliament on $date"; } @@ -149,7 +149,7 @@ protected function get_question_mentions_html($row_data) if(preg_match('/^uk.org.publicwhip\/spq\/(.*)$/', $row['mentioned_gid'], $m)) { $referencing_spid = $m[1]; $URL = new \MySociety\TheyWorkForYou\Url("spwrans"); - $URL->insert(array('spid' => $referencing_spid)); + $URL->insert(['spid' => $referencing_spid]); $relative_url = $URL->generate("none"); $inner = "Referenced in question $referencing_spid"; $reference = true; diff --git a/classes/SectionView/WhallView.php b/classes/SectionView/WhallView.php index 7bd33c80a6..5c6e8d47c6 100644 --- a/classes/SectionView/WhallView.php +++ b/classes/SectionView/WhallView.php @@ -9,6 +9,6 @@ class WhallView extends SectionView protected function front_content() { - return $this->list->display('biggest_debates', array('days' => 7, 'num' => 20), 'none'); + return $this->list->display('biggest_debates', ['days' => 7, 'num' => 20], 'none'); } } diff --git a/classes/SectionView/WmsView.php b/classes/SectionView/WmsView.php index fc146030e6..0207923db0 100644 --- a/classes/SectionView/WmsView.php +++ b/classes/SectionView/WmsView.php @@ -9,12 +9,12 @@ class WmsView extends SectionView protected function front_content() { - return $this->list->display('recent_wms', array('days' => 7, 'num' => 20), 'none'); + return $this->list->display('recent_wms', ['days' => 7, 'num' => 20], 'none'); } protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('wms'); $urls['day'] = $day; $urls['wmsday'] = $day; diff --git a/classes/SectionView/WransView.php b/classes/SectionView/WransView.php index 5489ce20aa..53ebcf953a 100644 --- a/classes/SectionView/WransView.php +++ b/classes/SectionView/WransView.php @@ -9,7 +9,7 @@ class WransView extends SectionView protected function front_content() { - return $this->list->display('recent_wrans', array('days' => 7, 'num' => 20), 'none'); + return $this->list->display('recent_wrans', ['days' => 7, 'num' => 20], 'none'); } protected function display_front() @@ -19,18 +19,18 @@ protected function display_front() return parent::display_front(); } - $data = array(); + $data = []; - $args = array( 'months' => 1 ); + $args = [ 'months' => 1 ]; $WRANSLIST = new \WRANSLIST(); - $wrans = array(); - $wrans['data'] = $WRANSLIST->display('recent_wrans', array('days' => 7, 'num' => 5), 'none'); + $wrans = []; + $wrans['data'] = $WRANSLIST->display('recent_wrans', ['days' => 7, 'num' => 5], 'none'); $wrans['calendar'] = $WRANSLIST->display('calendar', $args, 'none'); $WMSLIST = new \WMSLIST(); - $wms = array(); - $wms['data'] = $WMSLIST->display('recent_wms', array('days' => 7, 'num' => 20), 'none'); + $wms = []; + $wms['data'] = $WMSLIST->display('recent_wms', ['days' => 7, 'num' => 20], 'none'); $wms['calendar'] = $WMSLIST->display('calendar', $args, 'none'); $wms['rssurl'] = $DATA->page_metadata('wmsfront', 'rss'); @@ -43,7 +43,7 @@ protected function display_front() protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('wrans'); $urls['day'] = $day; $urls['wransday'] = $day; @@ -54,11 +54,11 @@ protected function getViewUrls() protected function getSearchSections() { - $sections = array( - array( 'section' => 'wrans', 'title' => 'Written Answers' ), - ); + $sections = [ + [ 'section' => 'wrans', 'title' => 'Written Answers' ], + ]; if (get_http_var('type') == '') { - $sections[] = array( 'section' => 'wms', 'title' => 'Written Ministerial Statements' ); + $sections[] = [ 'section' => 'wms', 'title' => 'Written Ministerial Statements' ]; } return $sections; } @@ -84,7 +84,7 @@ protected function generate_votes($votes, $id, $gid) return; } - $data = array(); + $data = []; if ($this->votelinks_so_far > 0 || strstr($gid, 'r')) { $yesvotes = $votes['user']['yes'] + $votes['anon']['yes']; $novotes = $votes['user']['no'] + $votes['anon']['no']; @@ -95,19 +95,19 @@ protected function generate_votes($votes, $id, $gid) $URL = new \MySociety\TheyWorkForYou\Url($this_page); $returl = $URL->generate(); $VOTEURL = new \MySociety\TheyWorkForYou\Url('epvote'); - $VOTEURL->insert(array('v' => '1', 'id' => $id, 'ret' => $returl)); + $VOTEURL->insert(['v' => '1', 'id' => $id, 'ret' => $returl]); $yes_vote_url = $VOTEURL->generate(); - $VOTEURL->insert(array('v' => '0')); + $VOTEURL->insert(['v' => '0']); $no_vote_url = $VOTEURL->generate(); - $data = array( + $data = [ 'yesvotes' => $yesvotes, 'yesplural' => $yesplural, 'yesvoteurl' => $yes_vote_url, 'novoteurl' => $no_vote_url, 'novotes' => $novotes, 'noplural' => $noplural, - ); + ]; } $this->votelinks_so_far++; diff --git a/classes/Topic.php b/classes/Topic.php index f72e18c963..965fcbda66 100644 --- a/classes/Topic.php +++ b/classes/Topic.php @@ -145,9 +145,9 @@ private function _getContentIDs() JOIN hansard h on ep.epobject_id = h.epobject_id JOIN topic_epobjects te on te.epobject_id = ep.epobject_id WHERE topic_key = :topic_key", - array( + [ ':topic_key' => $this->id, - ), + ], ); return $q; @@ -157,13 +157,13 @@ public function getContent() { $q = $this->_getContentIDs(); - $content = array(); + $content = []; foreach ($q as $row) { - $content[] = array( + $content[] = [ 'title' => $row['body'], 'href' => Utility\Hansard::gid_to_url($row['gid']), 'id' => $row['epobject_id'], - ); + ]; } return $content; @@ -173,7 +173,7 @@ public function getFullContent() { $q = $this->_getContentIDs(); - $content = array(); + $content = []; foreach ($q as $row) { $gid = $row['gid']; if (strpos($gid, 'lords') !== false) { @@ -183,7 +183,7 @@ public function getFullContent() } else { $debatelist = new \DEBATELIST(); } - $data = $debatelist->display('featured_gid', array('gid' => $gid), 'none'); + $data = $debatelist->display('featured_gid', ['gid' => $gid], 'none'); $item = $data['data']; if (isset($item['parent']) && $item['body'] == $item['parent']['body']) { @@ -199,9 +199,9 @@ public function addContent($gid) { $q = $this->db->query( "SELECT epobject_id FROM hansard WHERE gid = :gid", - array( + [ ":gid" => $gid, - ), + ], )->first(); if (!$q) { @@ -212,10 +212,10 @@ public function addContent($gid) $q = $this->db->query( "INSERT INTO topic_epobjects (topic_key, epobject_id) VALUES (:topic, :ep_id)", - array( + [ ":topic" => $this->id, ":ep_id" => $epobject_id, - ), + ], ); return $q->success(); @@ -225,10 +225,10 @@ public function deleteContent($id) { $q = $this->db->query( "DELETE FROM topic_epobjects WHERE topic_key = :topic AND epobject_id = :ep_id", - array( + [ ":topic" => $this->id, ":ep_id" => $id, - ), + ], ); return $q->success(); @@ -238,12 +238,12 @@ public function getPolicySets() { $q = $this->db->query( "SELECT policyset FROM topic_policysets WHERE topic_key = :key", - array( + [ ':key' => $this->id, - ), + ], ); - $sets = array(); + $sets = []; foreach ($q as $row) { $sets[] = $row['policyset']; } @@ -256,9 +256,9 @@ public function addPolicySets($sets) if ($sets === '' or count($sets) == 0) { $q = $this->db->query( "DELETE FROM topic_policysets WHERE topic_key = :topic_key", - array( + [ ":topic_key" => $this->id, - ), + ], ); } else { foreach ($sets as $set) { @@ -267,10 +267,10 @@ public function addPolicySets($sets) } $q = $this->db->query( "REPLACE INTO topic_policysets (policyset, topic_key) VALUES (:policyset, :topic_key)", - array( + [ ':topic_key' => $this->id, ':policyset' => $set, - ), + ], ); } } @@ -282,12 +282,12 @@ public function getPolicies() { $q = $this->db->query( 'SELECT policy_id FROM topic_policies WHERE topic_key = :key', - array( + [ ':key' => $this->id, - ), + ], ); - $policies = array(); + $policies = []; foreach ($q as $row) { $policies[] = $row['policy_id']; } @@ -300,9 +300,9 @@ public function addPolicies($policies) if ($policies === '' or count($policies) == 0) { $q = $this->db->query( "DELETE FROM topic_policies WHERE topic_key = :topic_key", - array( + [ ":topic_key" => $this->id, - ), + ], ); } else { foreach ($policies as $policy) { @@ -311,10 +311,10 @@ public function addPolicies($policies) } $q = $this->db->query( "REPLACE INTO topic_policies (policy_id, topic_key) VALUES (:policy, :topic_key)", - array( + [ ':topic_key' => $this->id, ':policy' => $policy, - ), + ], ); } } @@ -325,7 +325,7 @@ public function addPolicies($policies) public function getAllPolicies() { $policy_sets = $this->getPolicySets(); - $all_policies = array(); + $all_policies = []; $policies = new Policies(); foreach ($policy_sets as $set) { $all_policies = array_merge($all_policies, array_keys($policies->limitToSet($set)->getPolicies())); @@ -343,7 +343,7 @@ public function save() (id, title, slug, description, search_string, front_page, image) VALUES (:id, :title, :slug, :description, :search_string, :front_page, :image)", - array( + [ ':id' => $this->id, ':slug' => $this->slug(), ':title' => $this->title(), @@ -351,7 +351,7 @@ public function save() ':search_string' => $this->search_string(), ':front_page' => $this->onFrontPage(), ':image' => $this->image(), - ), + ], ); return $q->success(); diff --git a/classes/Topics.php b/classes/Topics.php index 69ca0a995a..339bc089ab 100644 --- a/classes/Topics.php +++ b/classes/Topics.php @@ -30,7 +30,7 @@ private function query($where = '') "SELECT id, slug, title, description, search_string, front_page, image FROM topics $where", ); - $topics = array(); + $topics = []; foreach ($q as $row) { $topic = $row; $topics[$topic['slug']] = new Topic($topic); @@ -47,7 +47,7 @@ public function getTopic($topic_name) { $q = $this->db->query( "SELECT id, slug, title, description, search_string, front_page, image FROM topics WHERE slug = :slug", - array(':slug' => $topic_name), + [':slug' => $topic_name], )->first(); if ($q) { return new Topic($q); @@ -64,7 +64,7 @@ public function getFrontPageTopics() public function updateFrontPageTopics($topics) { // PDO doesn't cope with arrays so we have to do this by hand :| - $quoted = array(); + $quoted = []; if ($topics) { foreach ($topics as $topic) { $quoted[] = $this->db->quote($topic); diff --git a/classes/Url.php b/classes/Url.php index 3b6dc77c1d..91b83325b8 100644 --- a/classes/Url.php +++ b/classes/Url.php @@ -43,7 +43,7 @@ public function __construct($pagename) // These stores an associative array of key/value pairs that // we'll want passed on to other pages. - $this->session_vars = array(); + $this->session_vars = []; // Prevent things using $DATA running if it hasn't been set, ie in testing if (isset($DATA)) { @@ -96,7 +96,7 @@ public function restore() public function reset() { // Call this to remove all the session_vars. - $this->session_vars = array(); + $this->session_vars = []; } /** @@ -168,12 +168,12 @@ public function update($arr) * override just one or two of them. */ - public function generate($encode = "html", $overrideVars = array()) + public function generate($encode = "html", $overrideVars = []) { global $DATA; - $url_args = array(); + $url_args = []; foreach (array_merge($this->session_vars, $overrideVars) as $key => $var) { if (is_array($var)) { diff --git a/classes/User.php b/classes/User.php index 8fdb4c9eb6..7890136a6b 100644 --- a/classes/User.php +++ b/classes/User.php @@ -49,11 +49,11 @@ public function getUserDetails($user_id = false) $valid = $user->init($user_id); if (!$valid || !$user->confirmed || $user->deleted()) { - return array('error' => 'User does not exist'); + return ['error' => 'User does not exist']; } } - $data = array(); + $data = []; $data['firstname'] = $user->firstname(); $data['lastname'] = $user->lastname(); $data['name'] = $user->firstname() . " " . $user->lastname(); @@ -77,7 +77,7 @@ public function getUserDetails($user_id = false) public function getUpdateDetails($this_page, $user) { - $details = array(); + $details = []; if ($user->facebook_user) { $details = $this->getUserDetails(); @@ -144,7 +144,7 @@ public function checkUpdateDetails($details) { global $THEUSER, $this_page; - $errors = array(); + $errors = []; // Check each of the things the user has input. // If there is a problem with any of them, set an entry in the $errors array. @@ -233,10 +233,10 @@ public function checkUpdateDetails($details) $errors["postcode"] = gettext("Sorry, this isn't a valid UK postcode."); } else { try { - new \MySociety\TheyWorkForYou\Member(array( + new \MySociety\TheyWorkForYou\Member([ 'postcode' => $details['postcode'], 'house' => HOUSE_TYPE_COMMONS, - )); + ]); } catch (MemberException $e) { $errors["postcode"] = gettext("Sorry, we could not find an MP for that postcode."); } @@ -263,7 +263,7 @@ public function update($details) { global $THEUSER, $this_page, $PAGE; - $results = array(); + $results = []; // There were no errors when the edit user form was submitted, // so make the changes in the DB. @@ -292,7 +292,7 @@ public function update($details) } else { - $results['errors'] = array("db" => "Sorry, we were unable to update $who details. Please let us know what you were trying to change. Thanks."); + $results['errors'] = ["db" => "Sorry, we were unable to update $who details. Please let us know what you were trying to change. Thanks."]; } return $results; @@ -308,7 +308,7 @@ public function add($details) // will be sent to them. $success = $THEUSER->add($details); - $errors = array(); + $errors = []; if (!$success) { $errors["db"] = "Sorry, we were unable to create an account for you. Please let us know. Thanks."; @@ -321,7 +321,7 @@ public function getRep($cons_type, $mp_house) { global $THEUSER; if (!$THEUSER->has_postcode()) { - return array(); + return []; } // User is logged in and has a postcode, or not logged in with a cookied postcode. @@ -335,22 +335,22 @@ public function getRep($cons_type, $mp_house) $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($THEUSER->postcode()); if (isset($constituencies[$cons_type])) { $constituency = $constituencies[$cons_type]; - $MEMBER = new Member(array('constituency' => $constituency, 'house' => $mp_house)); + $MEMBER = new Member(['constituency' => $constituency, 'house' => $mp_house]); } } catch (MemberException $e) { - return array(); + return []; } if (isset($MEMBER) && $MEMBER->valid) { return $this->constructMPData($MEMBER, $THEUSER, $mp_house); } - return array(); + return []; } private function constructMPData($member, $user, $mp_house) { - $mp_data = array(); + $mp_data = []; $mp_data['name'] = $member->full_name(); $mp_data['party'] = $member->party(); $mp_data['constituency'] = $member->constituency(); @@ -373,11 +373,11 @@ public function getRegionalReps($cons_type, $mp_house) { global $THEUSER; - $mreg = array(); + $mreg = []; if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) { $reps = \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, $mp_house, $cons_type); foreach ($reps as $rep) { - $member = new \MySociety\TheyWorkForYou\Member(array('person_id' => $rep['person_id'])); + $member = new \MySociety\TheyWorkForYou\Member(['person_id' => $rep['person_id']]); $mreg[$rep['person_id']] = $this->constructMPData($member, $THEUSER, $mp_house); } } diff --git a/classes/Utility/Alert.php b/classes/Utility/Alert.php index a89519bb9c..409e256ac2 100644 --- a/classes/Utility/Alert.php +++ b/classes/Utility/Alert.php @@ -12,7 +12,7 @@ class Alert { public static function detailsToCriteria($details) { - $criteria = array(); + $criteria = []; if (!empty($details['keyword'])) { $criteria[] = $details['keyword']; @@ -30,11 +30,11 @@ public static function forUser($email) { $db = new \ParlDB(); $q = $db->query('SELECT * FROM alerts WHERE email = :email - AND deleted != 1 ORDER BY created', array( + AND deleted != 1 ORDER BY created', [ ':email' => $email, - )); + ]); - $alerts = array(); + $alerts = []; foreach ($q as $row) { $criteria = self::prettifyCriteria($row['criteria']); $token = $row['alert_id'] . '-' . $row['registrationtoken']; @@ -46,12 +46,12 @@ public static function forUser($email) $status = 'suspended'; } - $alerts[] = array( + $alerts[] = [ 'token' => $token, 'status' => $status, 'criteria' => $criteria, 'raw' => $row['criteria'], - ); + ]; } return $alerts; @@ -62,7 +62,7 @@ public static function prettifyCriteria($alert_criteria) $text = ''; if ($alert_criteria) { $criteria = explode(' ', $alert_criteria); - $words = array(); + $words = []; $spokenby = array_values(\MySociety\TheyWorkForYou\Utility\Search::speakerNamesForIDs($alert_criteria)); foreach ($criteria as $c) { diff --git a/classes/Utility/Calendar.php b/classes/Utility/Calendar.php index 686ffba3be..c88ddf5e8b 100644 --- a/classes/Utility/Calendar.php +++ b/classes/Utility/Calendar.php @@ -53,7 +53,7 @@ public static function fetchDate($date) $PAGE->error_message('There is no information available for that date.', false, 404); } - return array(); + return []; } $DATA->set_page_metadata($this_page, 'date', $date); @@ -69,9 +69,9 @@ public static function fetchItem($id) private static function tidyData($q) { - $data = array(); - $seen = array(); - $people = array(); + $data = []; + $seen = []; + $people = []; foreach ($q as $row) { if ($row['person_id']) { $name = member_full_name($row['house'], $row['name_title'], $row['given_name'], $row['family_name'], $row['lordofname']); @@ -93,7 +93,7 @@ private static function tidyData($q) public static function displayEntry($e) { - list($title, $meta) = self::meta($e); + [$title, $meta] = self::meta($e); if (strstr($e['chamber'], 'Select Committee')) { print '
'; @@ -137,7 +137,7 @@ public static function meta($e) } } - $meta = array(); + $meta = []; if ($d = $e['debate_type']) { @@ -166,7 +166,7 @@ public static function meta($e) } } - return array($title, $meta); + return [$title, $meta]; } } diff --git a/classes/Utility/Constituencies.php b/classes/Utility/Constituencies.php index 8df2766c74..7453076c66 100644 --- a/classes/Utility/Constituencies.php +++ b/classes/Utility/Constituencies.php @@ -28,9 +28,9 @@ public static function normaliseConstituencyName($name) $name = str_replace("&", "&", $name); $query = "select cons_id from constituency where name like :name and from_date <= date(now()) and date(now()) <= to_date"; - $q1 = $db->query($query, array( + $q1 = $db->query($query, [ ':name' => $name, - ))->first(); + ])->first(); if (!$q1) { return false; } diff --git a/classes/Utility/Hansard.php b/classes/Utility/Hansard.php index 9c4fa9533e..8288625cac 100644 --- a/classes/Utility/Hansard.php +++ b/classes/Utility/Hansard.php @@ -38,10 +38,10 @@ public static function gid_to_url($gid) global $hansardmajors; $db = new \ParlDB(); - $q = $db->query("SELECT major FROM hansard WHERE gid = :gid", array( ':gid' => $gid ))->first(); + $q = $db->query("SELECT major FROM hansard WHERE gid = :gid", [ ':gid' => $gid ])->first(); $url_gid = fix_gid_from_db($gid); $url = new \MySociety\TheyWorkForYou\Url($hansardmajors[$q['major']]['page']); - $url->insert(array('id' => $url_gid)); + $url->insert(['id' => $url_gid]); return $url->generate(); } } diff --git a/classes/Utility/House.php b/classes/Utility/House.php index a253057920..d20c7b546e 100644 --- a/classes/Utility/House.php +++ b/classes/Utility/House.php @@ -12,119 +12,119 @@ class House { public static function division_house_name_to_number($name) { - $name_to_number = array( + $name_to_number = [ 'commons' => HOUSE_TYPE_COMMONS, 'lords' => HOUSE_TYPE_LORDS, 'scotland' => HOUSE_TYPE_SCOTLAND, 'pbc' => HOUSE_TYPE_COMMONS, 'senedd' => HOUSE_TYPE_WALES, - ); + ]; return $name_to_number[$name]; } public static function house_to_members($house) { - $house_to_members = array( - HOUSE_TYPE_COMMONS => array( + $house_to_members = [ + HOUSE_TYPE_COMMONS => [ 'singular' => 'MP', 'plural' => 'MPs', - ), - HOUSE_TYPE_LORDS => array( + ], + HOUSE_TYPE_LORDS => [ 'singular' => 'Member of the House of Lords', 'plural' => 'Members of the House of Lords', - ), - HOUSE_TYPE_NI => array( + ], + HOUSE_TYPE_NI => [ 'singular' => 'MLA', 'plural' => 'MLAs', - ), - HOUSE_TYPE_SCOTLAND => array( + ], + HOUSE_TYPE_SCOTLAND => [ 'singular' => 'MSP', 'plural' => 'MSPs', - ), - HOUSE_TYPE_WALES => array( + ], + HOUSE_TYPE_WALES => [ 'singular' => gettext('MS'), 'plural' => gettext('MSs'), - ), - HOUSE_TYPE_LONDON_ASSEMBLY => array( + ], + HOUSE_TYPE_LONDON_ASSEMBLY => [ 'singular' => 'Member of the London Assembly', 'plural' => 'Members of the London Assembly', - ), - ); + ], + ]; return $house_to_members[$house]; } public static function getCountryDetails($house) { - $details = array( - HOUSE_TYPE_COMMONS => array( + $details = [ + HOUSE_TYPE_COMMONS => [ 'country' => 'UK', 'assembly' => 'uk-commons', 'location' => '– in the House of Commons', 'cons_type' => 'WMC', 'assembly_name' => 'House of Commons', - ), - HOUSE_TYPE_NI => array( + ], + HOUSE_TYPE_NI => [ 'country' => 'NORTHERN IRELAND', 'assembly' => 'ni', 'location' => '– in the Northern Ireland Assembly', 'cons_type' => 'NIE', 'assembly_name' => 'Northern Ireland Assembly', - ), - HOUSE_TYPE_SCOTLAND => array( + ], + HOUSE_TYPE_SCOTLAND => [ 'country' => 'SCOTLAND', 'assembly' => 'scotland', 'location' => '– in the Scottish Parliament', 'cons_type' => 'SPC', 'assembly_name' => 'Scottish Parliament', - ), - HOUSE_TYPE_WALES => array( + ], + HOUSE_TYPE_WALES => [ 'country' => 'WALES', 'assembly' => 'wales', 'location' => '– in the Senedd', 'cons_type' => 'WAC', 'assembly_name' => 'Senedd', - ), - HOUSE_TYPE_LORDS => array( + ], + HOUSE_TYPE_LORDS => [ 'country' => 'UK', 'assembly' => 'uk-lords', 'location' => '– in the House of Lords', 'cons_type' => '', 'assembly_name' => 'House of Lords', - ), - HOUSE_TYPE_LONDON_ASSEMBLY => array( + ], + HOUSE_TYPE_LONDON_ASSEMBLY => [ 'country' => 'UK', 'assembly' => 'london-assembly', 'location' => '– in the London Assembly', 'cons_type' => 'LAS', 'assembly_name' => 'London Assembly', - ), - ); + ], + ]; if (!array_key_exists($house, $details)) { - return array('', '', '', '', ''); + return ['', '', '', '', '']; } $detail = $details[$house]; - return array($detail['country'], $detail['location'], $detail['assembly'], $detail['cons_type'], $detail['assembly_name']); + return [$detail['country'], $detail['location'], $detail['assembly'], $detail['cons_type'], $detail['assembly_name']]; } public static function majorToHouse($major) { - $major_to_house = array( - 1 => array(HOUSE_TYPE_COMMONS), - 2 => array(HOUSE_TYPE_COMMONS), - 3 => array(HOUSE_TYPE_COMMONS, HOUSE_TYPE_LORDS), - 4 => array(HOUSE_TYPE_COMMONS, HOUSE_TYPE_LORDS), - 5 => array(HOUSE_TYPE_NI), - 6 => array(HOUSE_TYPE_COMMONS), - 7 => array(HOUSE_TYPE_SCOTLAND), - 8 => array(HOUSE_TYPE_SCOTLAND), - 9 => array(HOUSE_TYPE_LONDON_ASSEMBLY), - 10 => array(HOUSE_TYPE_WALES), - 11 => array(HOUSE_TYPE_WALES), - 101 => array(HOUSE_TYPE_LORDS), - ); + $major_to_house = [ + 1 => [HOUSE_TYPE_COMMONS], + 2 => [HOUSE_TYPE_COMMONS], + 3 => [HOUSE_TYPE_COMMONS, HOUSE_TYPE_LORDS], + 4 => [HOUSE_TYPE_COMMONS, HOUSE_TYPE_LORDS], + 5 => [HOUSE_TYPE_NI], + 6 => [HOUSE_TYPE_COMMONS], + 7 => [HOUSE_TYPE_SCOTLAND], + 8 => [HOUSE_TYPE_SCOTLAND], + 9 => [HOUSE_TYPE_LONDON_ASSEMBLY], + 10 => [HOUSE_TYPE_WALES], + 11 => [HOUSE_TYPE_WALES], + 101 => [HOUSE_TYPE_LORDS], + ]; return $major_to_house[$major]; } diff --git a/classes/Utility/LibFilter.php b/classes/Utility/LibFilter.php index 461558b1d3..d78ceaa44e 100644 --- a/classes/Utility/LibFilter.php +++ b/classes/Utility/LibFilter.php @@ -23,63 +23,63 @@ class LibFilter { - public $tag_counts = array(); + public $tag_counts = []; # # tags and attributes that are allowed # - public $allowed = array( - 'a' => array('href', 'target'), - 'b' => array(), - 'img' => array('src', 'width', 'height', 'alt'), - ); + public $allowed = [ + 'a' => ['href', 'target'], + 'b' => [], + 'img' => ['src', 'width', 'height', 'alt'], + ]; # # tags which should always be self-closing (e.g. "") # - public $no_close = array( + public $no_close = [ 'img', - ); + ]; # # tags which must always have seperate opening and closing tags (e.g. "") # - public $always_close = array( + public $always_close = [ 'a', 'b', - ); + ]; # # attributes which should be checked for valid protocols # - public $protocol_attributes = array( + public $protocol_attributes = [ 'src', 'href', - ); + ]; # # protocols which are allowed # - public $allowed_protocols = array( + public $allowed_protocols = [ 'http', 'https', 'ftp', 'mailto', - ); + ]; # # tags which should be removed if they contain no content (e.g. "" or "") # - public $remove_blanks = array( + public $remove_blanks = [ 'a', 'b', - ); + ]; # # should we remove comments? @@ -105,12 +105,12 @@ class LibFilter # converted from '&foo;' to '&foo;' # - public $allowed_entities = array( + public $allowed_entities = [ 'amp', 'gt', 'lt', 'quot', - ); + ]; # # should we convert dec/hex entities in the general doc (not inside protocol attribute) @@ -134,7 +134,7 @@ class LibFilter public function go($data) { - $this->tag_counts = array(); + $this->tag_counts = []; $data = $this->escape_comments($data); $data = $this->balance_html($data); @@ -381,7 +381,7 @@ public function fix_case($data) return preg_replace_callback( "/(>|^)([^<]+?)(<|$)/s", - array($this, 'fix_case_inner'), + [$this, 'fix_case_inner'], $data, ); } @@ -463,7 +463,7 @@ public function cleanup_non_tags($data) return preg_replace_callback( "/(>|^)([^<]+?)(<|$)/s", - array($this, 'cleanup_non_tags_inner'), + [$this, 'cleanup_non_tags_inner'], $data, ); @@ -581,11 +581,11 @@ public function is_valid_entity($entity) public function decode_entities($data, $in_attribute = 1) { - $data = preg_replace_callback('!(&)#(\d+);?!', array($this, 'decode_dec_entity'), $data); - $data = preg_replace_callback('!(&)#x([0-9a-f]+);?!i', array($this, 'decode_hex_entity'), $data); + $data = preg_replace_callback('!(&)#(\d+);?!', [$this, 'decode_dec_entity'], $data); + $data = preg_replace_callback('!(&)#x([0-9a-f]+);?!i', [$this, 'decode_hex_entity'], $data); if ($in_attribute) { - $data = preg_replace_callback('!(%)([0-9a-f]{2});?!i', array($this, 'decode_hex_entity'), $data); + $data = preg_replace_callback('!(%)([0-9a-f]{2});?!i', [$this, 'decode_hex_entity'], $data); } return $data; @@ -646,7 +646,7 @@ public function decode_num_entity($orig_type, $d) public function StripSingle($data) { - return str_replace(array('\\"', "\\0"), array('"', chr(0)), $data); + return str_replace(['\\"', "\\0"], ['"', chr(0)], $data); } ##################################################################################### diff --git a/classes/Utility/Member.php b/classes/Utility/Member.php index b7af294f49..746aa1b396 100644 --- a/classes/Utility/Member.php +++ b/classes/Utility/Member.php @@ -64,7 +64,7 @@ public static function findMemberImage($pid, $smallonly = false, $substitute_mis $sz = 'L'; } } - return array($image, $sz); + return [$image, $sz]; } } diff --git a/classes/Utility/Postcode.php b/classes/Utility/Postcode.php index 8508046d97..6503725f0e 100644 --- a/classes/Utility/Postcode.php +++ b/classes/Utility/Postcode.php @@ -73,9 +73,9 @@ private static function postcodeToConstituenciesInternal($postcode, $mp_only) private static function postcodeFetchFromDb($postcode) { $db = new \ParlDB(); - $q = $db->query('select name from postcode_lookup where postcode = :postcode', array( + $q = $db->query('select name from postcode_lookup where postcode = :postcode', [ ':postcode' => $postcode, - ))->first(); + ])->first(); if ($q) { $name = $q['name']; @@ -87,13 +87,13 @@ private static function postcodeFetchFromDb($postcode) } $name = explode('|', $name); if ($country == 'W') { - return array('WMC' => $name[0], 'WAC' => $name[1], 'WAE' => $name[2]); + return ['WMC' => $name[0], 'WAC' => $name[1], 'WAE' => $name[2]]; } elseif ($country == 'S' || count($name) == 3) { - return array('WMC' => $name[0], 'SPC' => $name[1], 'SPE' => $name[2]); + return ['WMC' => $name[0], 'SPC' => $name[1], 'SPE' => $name[2]]; } elseif ($country == 'N' || count($name) == 2) { - return array('WMC' => $name[0], 'NIE' => $name[1]); + return ['WMC' => $name[0], 'NIE' => $name[1]]; } else { - return array('WMC' => $name[0]); + return ['WMC' => $name[0]]; } } } @@ -131,9 +131,9 @@ private static function postcodeFetchFromMapit($postcode) if (isset($r['error']) || !isset($r['areas'])) { return ''; } - $areas = array(); + $areas = []; foreach ($r['areas'] as $row) { - if (in_array($row['type'], array('WMC', 'SPC', 'SPE', 'NIE', 'WAC', 'WAE'))) { + if (in_array($row['type'], ['WMC', 'SPC', 'SPE', 'NIE', 'WAC', 'WAE'])) { $areas[$row['type']] = $row['name']; } } @@ -158,10 +158,10 @@ private static function postcodeFetchFromMapit($postcode) $db = new \ParlDB(); $db->query( 'replace into postcode_lookup values(:postcode, :serialized)', - array( + [ ':postcode' => $postcode, ':serialized' => $serialized, - ), + ], ); } else { return ''; diff --git a/classes/Utility/Search.php b/classes/Utility/Search.php index e1e18041d5..ba4d21a93c 100644 --- a/classes/Utility/Search.php +++ b/classes/Utility/Search.php @@ -12,7 +12,7 @@ class Search { public static function searchByUsage($search, $house = 0) { - $data = array(); + $data = []; $SEARCHENGINE = new \SEARCHENGINE($search); $data['pagetitle'] = $SEARCHENGINE->query_description_short(); $SEARCHENGINE = new \SEARCHENGINE($search . ' groupby:speech'); @@ -34,7 +34,7 @@ public static function searchByUsage($search, $house = 0) } # Fetch all the speakers of the results, count them up and get min/max date usage - $speaker_count = array(); + $speaker_count = []; $gids = join('","', $gids); $db = new \ParlDB(); $q = $db->query('SELECT person_id,hdate FROM hansard WHERE gid IN ("' . $gids . '")'); @@ -56,8 +56,8 @@ public static function searchByUsage($search, $house = 0) } # Fetch details of all the speakers - $speakers = array(); - $pids = array(); + $speakers = []; + $pids = []; if (count($speaker_count)) { $person_ids = join(',', array_keys($speaker_count)); $q = $db->query('SELECT member_id, member.person_id, title, given_name, family_name, lordofname, @@ -98,9 +98,9 @@ public static function searchByUsage($search, $house = 0) } } if (isset($speaker_count[0])) { - $speakers[0] = array('party' => '', 'name' => 'Headings, procedural text, etc.', 'house' => 0, 'count' => 0); + $speakers[0] = ['party' => '', 'name' => 'Headings, procedural text, etc.', 'house' => 0, 'count' => 0]; } - $party_count = array(); + $party_count = []; $ok = 0; foreach ($speakers as $pid => &$speaker) { $speaker['count'] = $speaker_count[$pid]; @@ -148,10 +148,10 @@ public static function searchByUsage($search, $house = 0) public static function searchMemberDbLookup($searchstring, $current_only = false) { if (!$searchstring) { - return array(); + return []; } $searchwords = explode(' ', $searchstring, 3); - $params = array(); + $params = []; if (count($searchwords) == 1) { $params[':like_0'] = '%' . $searchwords[0] . '%'; $where = "given_name LIKE :like_0 OR family_name LIKE :like_0 OR lordofname LIKE :like_0"; @@ -192,12 +192,12 @@ public static function searchMemberDbLookup($searchstring, $current_only = false $q = $db->query("SELECT person_id FROM person_names WHERE type='name' AND ($where)", $params); # Check for redirects - $pids = array(); + $pids = []; foreach ($q as $row) { $pid = $row['person_id']; $redirect = $db->query( "SELECT gid_to FROM gidredirect WHERE gid_from = :gid_from", - array(':gid_from' => "uk.org.publicwhip/person/$pid"), + [':gid_from' => "uk.org.publicwhip/person/$pid"], )->first(); if ($redirect) { $pid = str_replace('uk.org.publicwhip/person/', '', $redirect['gid_to']); @@ -259,7 +259,7 @@ public static function searchConstituenciesByQuery($searchterm) // Looks like a postcode - can we find the constituency? $constituency = Postcode::postcodeToConstituency($searchterm); if ($constituency) { - return array( array($constituency), true ); + return [ [$constituency], true ]; } } @@ -270,14 +270,14 @@ public static function searchConstituenciesByQuery($searchterm) from constituency AS o where name like :try and from_date <= date(now()) and date(now()) <= to_date"; $db = new \ParlDB(); - $q = $db->query($query, array(':try' => '%' . $try . '%')); + $q = $db->query($query, [':try' => '%' . $try . '%']); - $constituencies = array(); + $constituencies = []; foreach ($q as $row) { $constituencies[] = $row['name']; } - return array( $constituencies, false ); + return [ $constituencies, false ]; } /** @@ -295,7 +295,7 @@ public static function speakerNamesForIDs($searchstring) foreach ($criteria as $c) { if (preg_match('#^speaker:(\d+)#', $c, $m)) { - $MEMBER = new \MEMBER(array('person_id' => $m[1])); + $MEMBER = new \MEMBER(['person_id' => $m[1]]); $speakers[$m[1]] = $MEMBER->full_name(); } } diff --git a/classes/Utility/Shuffle.php b/classes/Utility/Shuffle.php index c8dca58cc6..eb2b6d16bd 100644 --- a/classes/Utility/Shuffle.php +++ b/classes/Utility/Shuffle.php @@ -8,7 +8,7 @@ public static function keyValue($arr) { $keys = array_keys($arr); shuffle($keys); - $new = array(); + $new = []; foreach ($keys as $key) { $new[$key] = $arr[$key]; } diff --git a/classes/Utility/Wikipedia.php b/classes/Utility/Wikipedia.php index eba9772b54..5cf1629b20 100644 --- a/classes/Utility/Wikipedia.php +++ b/classes/Utility/Wikipedia.php @@ -84,7 +84,7 @@ public static function wikipedize($source) } // Assemble the resulting phrases into a parameter array - $params = array(); + $params = []; foreach ($phrases as $i => $phrase) { $params[':phrase' . $i] = $phrase; } @@ -98,11 +98,11 @@ public static function wikipedize($source) # Open up a db connection, and whittle our list down even further, against # the real titles. - $matched = array(); + $matched = []; $db = new \ParlDB(); $source = explode('|||', $source); $q = $db->query("SELECT titles.title FROM titles LEFT JOIN titles_ignored ON titles.title=titles_ignored.title WHERE titles.title IN (" . join(',', array_keys($params)) . ") AND titles_ignored.title IS NULL", $params); - $phrases = array(); + $phrases = []; foreach ($q as $row) { $phrases[] = $row['title']; } diff --git a/scripts/alertgonemps.php b/scripts/alertgonemps.php index e26c8ad5bb..a2e3723287 100644 --- a/scripts/alertgonemps.php +++ b/scripts/alertgonemps.php @@ -62,8 +62,8 @@ function mlog($message) $LIVEALERTS = new ALERT(); -$current = array('email' => '', 'token' => ''); -$email_text = array(); +$current = ['email' => '', 'token' => '']; +$email_text = []; $globalsuccess = 1; # Fetch all confirmed, non-deleted alerts @@ -73,7 +73,7 @@ function mlog($message) $alertdata = $alertdata['data']; $outof = count($alertdata); -$members = array(); +$members = []; $start_time = time(); foreach ($alertdata as $alertitem) { $active++; @@ -100,7 +100,7 @@ function mlog($message) $person_id = $m[1]; if (!isset($members[$person_id])) { $queries++; - $members[$person_id] = new MEMBER(array('person_id' => $person_id)); + $members[$person_id] = new MEMBER(['person_id' => $person_id]); } $member = $members[$person_id]; if ($member->current_member_anywhere()) { @@ -113,9 +113,9 @@ function mlog($message) } $current['email'] = $email; $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; - $email_text = array(); - $q = $db->query('SELECT user_id FROM users WHERE email = :email', array( - ':email' => $email))->first(); + $email_text = []; + $q = $db->query('SELECT user_id FROM users WHERE email = :email', [ + ':email' => $email])->first(); if ($q) { $user_id = $q['user_id']; $registered++; @@ -155,13 +155,13 @@ function write_and_send_email($current, $data, $template) $sentemails++; mlog("SEND $sentemails : Sending email to $current[email] ... "); - $d = array('to' => $current['email'], 'template' => $template); - $m = array( + $d = ['to' => $current['email'], 'template' => $template]; + $m = [ 'DATA' => join("\n", $data), 'MANAGE' => 'https://www.theyworkforyou.com/D/' . $current['token'], 'ALERT_IS' => count($data) == 1 ? 'alert is' : 'alerts are', 'ALERTS' => count($data) == 1 ? 'an alert' : 'some alerts', - ); + ]; if (!$nomail) { $success = send_template_email($d, $m, true); mlog("sent ... "); diff --git a/scripts/alertmailer.php b/scripts/alertmailer.php index e385da1bda..8414a3389e 100644 --- a/scripts/alertmailer.php +++ b/scripts/alertmailer.php @@ -27,7 +27,7 @@ function mlog($message) if (is_file(RAWDATA . '/alerts-lastsent')) { $lastsent = file(RAWDATA . '/alerts-lastsent'); } else { - $lastsent = array('', 0); + $lastsent = ['', 0]; } $lastupdated = trim($lastsent[0]); @@ -101,7 +101,7 @@ function mlog($message) $LIVEALERTS = new ALERT(); -$current = array('email' => '', 'token' => '', 'lang' => ''); +$current = ['email' => '', 'token' => '', 'lang' => '']; $email_text = ''; $html_text = ''; $globalsuccess = 1; @@ -114,7 +114,7 @@ function mlog($message) $DEBATELIST = new DEBATELIST(); # Nothing debate specific, but has to be one of them -$sects = array( +$sects = [ 1 => gettext('Commons debate'), 2 => gettext('Westminster Hall debate'), 3 => gettext('Written Answer'), @@ -129,8 +129,8 @@ function mlog($message) 101 => gettext('Lords debate'), 'F' => gettext('event'), 'V' => gettext('vote'), -); -$sects_plural = array( +]; +$sects_plural = [ 1 => gettext('Commons debates'), 2 => gettext('Westminster Hall debates'), 3 => gettext('Written Answers'), @@ -145,8 +145,8 @@ function mlog($message) 101 => gettext('Lords debate'), 'F' => gettext('event'), 'V' => gettext('vote'), -); -$sects_gid = array( +]; +$sects_gid = [ 1 => 'debate', 2 => 'westminhall', 3 => 'wrans', @@ -160,8 +160,8 @@ function mlog($message) 11 => 'senedd/cy', 101 => 'lords', 'F' => 'calendar', -); -$sects_search = array( +]; +$sects_search = [ 1 => 'debate', 2 => 'westminhall', 3 => 'wrans', @@ -175,7 +175,7 @@ function mlog($message) 11 => 'wales', 101 => 'lords', 'F' => 'future', -); +]; $domain = ''; $outof = count($alertdata); @@ -219,9 +219,9 @@ function mlog($message) $current['lang'] = $lang; $email_text = ''; $html_text = ''; - $q = $db->query('SELECT user_id FROM users WHERE email = :email', array( + $q = $db->query('SELECT user_id FROM users WHERE email = :email', [ ':email' => $email, - ))->first(); + ])->first(); if ($q) { $user_id = $q['user_id']; $registered++; @@ -236,14 +236,14 @@ function mlog($message) $start = getmicrotime(); $SEARCHENGINE = new SEARCHENGINE($criteria_batch, $lang); #mlog("query_remade: " . $SEARCHENGINE->query_remade() . "\n"); - $args = array( + $args = [ 's' => $criteria_raw, # Note: use raw here for URLs, whereas search engine has batch 'threshold' => $lastupdated, # Return everything added since last time this script was run 'o' => 'c', 'num' => 1000, // this is limited to 1000 in hansardlist.php anyway 'pop' => 1, 'e' => 1, # Don't escape ampersands - ); + ]; $data = $DEBATELIST->_get_data_by_search($args); $total_results = $data['info']['total_results']; $queries++; @@ -253,10 +253,10 @@ function mlog($message) if (preg_match('#^speaker:(\d+)$#', $criteria_raw, $m)) { $pid = $m[1]; $q = $db->query('SELECT * FROM persondivisionvotes pdv JOIN divisions USING(division_id) - WHERE person_id=:person_id AND pdv.lastupdate >= :time', array( + WHERE person_id=:person_id AND pdv.lastupdate >= :time', [ 'person_id' => $pid, ':time' => date('Y-m-d H:i:s', $lastupdated), - )); + ]); foreach ($q as $row) { # Skip other-language divisions if needed, set locale if (strpos($row['division_id'], '-cy-')) { @@ -312,9 +312,9 @@ function mlog($message) if (isset($data['rows']) && count($data['rows']) > 0) { usort($data['rows'], 'sort_by_stuff'); # Sort results into order, by major, then date, then hpos - $o = array(); + $o = []; $major = 0; - $count = array(); + $count = []; $total = 0; $any_content = false; foreach ($data['rows'] as $row) { @@ -328,9 +328,9 @@ function mlog($message) #mlog($row['major'] . " " . $row['gid'] ."\n"); if (isset($sects_gid[$major])) { - $q = $db->query('SELECT gid_from FROM gidredirect WHERE gid_to = :gid_to', array( + $q = $db->query('SELECT gid_from FROM gidredirect WHERE gid_to = :gid_to', [ ':gid_to' => 'uk.org.publicwhip/' . $sects_gid[$major] . '/' . $row['gid'], - )); + ]); if ($q->rows() > 0) { continue; } @@ -470,12 +470,12 @@ function write_and_send_email($current, $text, $html, $template) $text .= '===================='; $sentemails++; mlog("SEND $sentemails : Sending email to $current[email] ... "); - $d = array('to' => $current['email'], 'template' => $template); - $m = array( + $d = ['to' => $current['email'], 'template' => $template]; + $m = [ 'DATA' => $text, '_HTML_' => $html, 'MANAGE' => "https://$domain/D/" . $current['token'], - ); + ]; if (!$nomail) { $success = send_template_email($d, $m, true, true, $current['lang']); # true = "Precedence: bulk", want bounces mlog("sent ... "); @@ -500,8 +500,8 @@ function text_html_to_email($s) $s = preg_replace('##', '', $s); $s = preg_replace('#]*>#', '*', $s); $s = str_replace( - array('£', '–', '—', '’', '
'), - array("\xa3", '-', '-', "'", "\n"), + ['£', '–', '—', '’', '
'], + ["\xa3", '-', '-', "'", "\n"], $s, ); return $s; diff --git a/scripts/alertmpchanged.php b/scripts/alertmpchanged.php index c62c6fbfda..552dfff3f0 100644 --- a/scripts/alertmpchanged.php +++ b/scripts/alertmpchanged.php @@ -60,9 +60,9 @@ function mlog($message) $LIVEALERTS = new ALERT(); -$current = array('email' => '', 'token' => ''); -$email_text = array(); -$change_text = array(); +$current = ['email' => '', 'token' => '']; +$email_text = []; +$change_text = []; $globalsuccess = 1; # Fetch all confirmed, non-deleted alerts @@ -72,7 +72,7 @@ function mlog($message) $alertdata = $alertdata['data']; $outof = count($alertdata); -$members = array(); +$members = []; $start_time = time(); foreach ($alertdata as $alertitem) { $active++; @@ -100,7 +100,7 @@ function mlog($message) $person_id = $m[1]; if (!isset($members[$person_id])) { $queries++; - $members[$person_id] = new MEMBER(array('person_id' => $person_id)); + $members[$person_id] = new MEMBER(['person_id' => $person_id]); } $member = $members[$person_id]; @@ -115,7 +115,7 @@ function mlog($message) } if (!isset($cons[$member->constituency])) { - $cons_member = new MEMBER(array('constituency' => $member->constituency, 'house' => 1)); + $cons_member = new MEMBER(['constituency' => $member->constituency, 'house' => 1]); if (!$cons_member) { continue; } @@ -138,10 +138,10 @@ function mlog($message) } $current['email'] = $email; $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; - $email_text = array(); - $change_text = array(); - $q = $db->query('SELECT user_id FROM users WHERE email = :email', array( - ':email' => $email))->first(); + $email_text = []; + $change_text = []; + $q = $db->query('SELECT user_id FROM users WHERE email = :email', [ + ':email' => $email])->first(); if ($q) { $user_id = $q['user_id']; $registered++; @@ -184,8 +184,8 @@ function write_and_send_email($current, $data, $change, $template) $sentemails++; mlog("SEND $sentemails : Sending email to $current[email] ... "); - $d = array('to' => $current['email'], 'template' => $template); - $m = array( + $d = ['to' => $current['email'], 'template' => $template]; + $m = [ 'DATA' => join("\n", $data), 'CHANGE' => join("\n", $change), 'ALERT_IS' => count($data) == 1 ? 'alert is' : 'alerts are', @@ -194,7 +194,7 @@ function write_and_send_email($current, $data, $change, $template) 'ALERTS' => count($data) == 1 ? 'an alert' : 'some alerts', 'ALERTS2' => count($data) == 1 ? 'alert' : 'alerts', 'LINKS' => count($data) == 1 ? 'link' : 'links', - ); + ]; if (!$nomail) { $success = send_template_email($d, $m, true); mlog("sent ... "); diff --git a/scripts/create_initial_topics.php b/scripts/create_initial_topics.php index b379d3a96e..67abc5b92b 100644 --- a/scripts/create_initial_topics.php +++ b/scripts/create_initial_topics.php @@ -6,8 +6,8 @@ $topics = new MySociety\TheyWorkForYou\Topics(); -$all_topics = array( - 'benefits' => array( +$all_topics = [ + 'benefits' => [ 'title' => 'Benefits', 'page' => 'topicbenefits', 'blurb' => 'Benefits are a major political issue right now - they @@ -15,81 +15,81 @@ where to find the important debates.', 'policyset' => 'welfare', 'policytitle' => 'Welfare and Benefits', - 'actions' => array( + 'actions' => [ - array( + [ 'title' => 'Universal Credit Regulations', 'icon' => 'debate', 'href' => 'https://www.theyworkforyou.com/lords/?id=2013-02-13a.664.3', 'blurb' => 'Lords debate, and approve, the consolidation of all benefits into the Universal Credit system.', - ), + ], - array( + [ 'title' => 'Welfare Benefits Up-rating Bill', 'icon' => 'bill', 'href' => 'https://www.theyworkforyou.com/lords/?id=2013-02-11a.457.8', 'blurb' => 'Lords debate a cap on annual increases to working-age benefits.', - ), + ], - array( + [ 'title' => 'Search the whole site', 'icon' => 'search', 'href' => 'https://www.theyworkforyou.com/search/?s=%22benefits%22', 'blurb' => 'Search TheyWorkForYou to find mentions of benefits. You may also filter your results by time, speaker and section.', - ), + ], - array( + [ 'title' => 'Sign up for email alerts', 'icon' => 'alert', 'href' => 'https://www.theyworkforyou.com/alert/?alertsearch=%22benefits%22', 'blurb' => 'We’ll let you know every time benefits are mentioned in Parliament.', - ), + ], - ), + ], - ), + ], - 'crime-stats' => array( + 'crime-stats' => [ 'title' => 'Crime Statistics', 'page' => 'topiccrimestats', 'blurb' => 'MPs and Lords often talk about Crime Statistics, because they’re a major political issue.', - 'actions' => array( + 'actions' => [ - array( + [ 'title' => 'Anti-social Behaviour Crime and Policing Bill (second reading)', 'icon' => 'bill', 'href' => 'https://www.theyworkforyou.com/lords/?id=2013-10-29a.1482.5', 'blurb' => 'The House of Lords debate a proposed law, making many references to crime statistics.', - ), + ], - array( + [ 'title' => 'Police and Public trust', 'icon' => 'debate', 'href' => 'https://www.theyworkforyou.com/lords/?id=2013-11-28a.1576.0', 'blurb' => 'A debate on police misconduct and how much the general public trust the police not to cover up crime statistics, mistakes and misbehaviour.', - ), + ], - array( + [ 'title' => 'Search the whole site', 'icon' => 'search', 'href' => 'https://www.theyworkforyou.com/search/?s=%22crime+statistics%22', 'blurb' => 'Search TheyWorkForYou to find mentions of crime statistics. You may also filter your results by time, speaker and section.', - ), + ], - array( + [ 'title' => 'Sign up for email alerts', 'icon' => 'alert', 'href' => 'https://www.theyworkforyou.com/alert/?alertsearch=%22crime+statistics%22', 'blurb' => 'We’ll let you know every time crime statistics are mentioned in Parliament.', - ), + ], - ), + ], - ), + ], - 'nhs' => array( + 'nhs' => [ 'title' => 'The NHS', 'page' => 'topicnhs', 'blurb' => 'The NHS is a major political issue right now — @@ -97,40 +97,40 @@ exactly where to find the important debates.', 'policyset' => 'health', 'policytitle' => 'Healthcare', - 'actions' => array( + 'actions' => [ - array( + [ 'title' => 'Health and Social Care Bill', 'icon' => 'debate', 'href' => 'https://www.theyworkforyou.com/debates/?id=2011-01-31b.605.0', 'blurb' => 'Andrew Lansley, Secretary of State for Health, sets out plans for a reorganisation of the NHS, which MPs then debate and vote on.', - ), + ], - array( + [ 'title' => 'NHS (Private Sector)', 'icon' => 'debate', 'href' => 'https://www.theyworkforyou.com/debates/?id=2012-01-16a.536.0', 'blurb' => 'A year later, the opposition puts forward its concerns with the model, ending in a further vote.', - ), + ], - array( + [ 'title' => 'Search the whole site', 'icon' => 'search', 'href' => 'https://www.theyworkforyou.com/search/?s=%22nhs%22', 'blurb' => 'Search TheyWorkForYou to find mentions of the NHS. You may also filter your results by time, speaker and section.', - ), + ], - array( + [ 'title' => 'Sign up for email alerts', 'icon' => 'alert', 'href' => 'https://www.theyworkforyou.com/alert/?alertsearch=%nhs%22', 'blurb' => 'We’ll let you know every time the NHS is mentioned in Parliament.', - ), + ], - ), + ], - ), -); + ], +]; foreach ($all_topics as $name => $topic) { $existing = $topics->getTopic($name); diff --git a/scripts/mprss.php b/scripts/mprss.php index 32531f4745..ff5482cc2d 100755 --- a/scripts/mprss.php +++ b/scripts/mprss.php @@ -24,13 +24,13 @@ foreach ($q as $person) { $person_id = $person['person_id']; - $args = array( 'person_id' => $person_id ); + $args = [ 'person_id' => $person_id ]; $speeches = $HANSARDLIST->display('person', $args, 'none'); // Some data about this person that we'll need for the feed. - $MEMBER = new MEMBER(array('person_id' => $person_id)); + $MEMBER = new MEMBER(['person_id' => $person_id]); $MPURL = new \MySociety\TheyWorkForYou\Url('mp'); - $MPURL->insert(array('pid' => $person_id)); + $MPURL->insert(['pid' => $person_id]); $mpurl = $MPURL->generate(); $date = gmdate('Y-m-d'); @@ -48,7 +48,7 @@ // the text is the body of the parent, ie (sub)section. $title = _htmlentities(str_replace('—', '-', $row['parent']['body'])); - $link = isset($row['listurl']) ? $row['listurl'] : ''; + $link = $row['listurl'] ?? ''; $link = 'https://' . DOMAIN . $link; $description = _htmlentities(trim_characters($row['body'], 0, 200)); diff --git a/scripts/populate-policy-images.php b/scripts/populate-policy-images.php index 9d41646173..e7b784ee20 100755 --- a/scripts/populate-policy-images.php +++ b/scripts/populate-policy-images.php @@ -26,7 +26,7 @@ $ARGV = $_SERVER['argv']; $db = new ParlDB(); -$csvfile = isset($ARGV[1]) ? $ARGV[1] : ''; +$csvfile = $ARGV[1] ?? ''; if (!$csvfile) { print "Need a csv file with policy details\n"; @@ -62,14 +62,14 @@ image_license_url = :license_url, title = :title, description = :description WHERE policy_id = :policy_id ", - array( + [ ':policy_id' => $policy_id, ':title' => $title, ':description' => $description, ':image' => "/images/policies/" . $img_id . ".jpg", ':image_source' => $source, ':image_attribution' => $attribution, - ':license_url' => $licence_url), + ':license_url' => $licence_url], ); if ($q->success()) { $count += $q->affected_rows(); diff --git a/scripts/wrans-votes-by-dept.php b/scripts/wrans-votes-by-dept.php index 5d8317af48..b6a41c29a5 100644 --- a/scripts/wrans-votes-by-dept.php +++ b/scripts/wrans-votes-by-dept.php @@ -23,13 +23,13 @@ #echo "Number of answers with votes: $rows\n"; #echo "Number of answers in system: $answers\n"; -$votes = array(); +$votes = []; while ($row = mysql_fetch_assoc($q)) { $dept = $row['body']; if (!isset($votes[$dept])) { - $votes[$dept] = array( + $votes[$dept] = [ 'verymoreyes' => 0, 'moreyes' => 0, 'verymoreno' => 0, 'moreno' => 0, 'same' => 0, 'none' => 0, - ); + ]; } $yes = $row['yes_votes']; $no = $row['no_votes']; diff --git a/tests/AcceptApiTest.php b/tests/AcceptApiTest.php index ca9b0a4900..84428c3158 100644 --- a/tests/AcceptApiTest.php +++ b/tests/AcceptApiTest.php @@ -13,18 +13,18 @@ public function getDataSet() return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/api.xml'); } - private function fetch_page($method, $vars = array()) + private function fetch_page($method, $vars = []) { $vars['method'] = $method; return $this->base_fetch_page($vars, 'api'); } - private function get_page($page, $vars = array()) + private function get_page($page, $vars = []) { return $this->base_fetch_page_user($vars, '1.fbb689a0c092f5534b929d302db2c8a9', 'api', "$page.php"); } - private function post_page($page, $vars = array()) + private function post_page($page, $vars = []) { return $this->base_post_page_user($vars, '1.fbb689a0c092f5534b929d302db2c8a9', 'api', "$page.php"); } @@ -43,18 +43,18 @@ public function testMissingKeyFailure() */ public function testIncorrectKeyFailure() { - $page = $this->fetch_page('getConstituencies', array( + $page = $this->fetch_page('getConstituencies', [ 'key' => 'invalid_key', - )); + ]); $this->assertEquals('{"error":"Invalid API key."}', $page); } private function _testGetJSON($page, $key, $value, $result) { - $page = $this->fetch_page($page, array( + $page = $this->fetch_page($page, [ 'key' => 'test_key', $key => $value, - )); + ]); $this->assertNotNull(json_decode($page)); $this->assertNotNull(json_decode($result)); $this->assertEquals(json_decode($result), json_decode($page)); @@ -161,13 +161,13 @@ public function testApiKeySignup() { $page = $this->post_page('key'); $this->assertStringContainsString('Subscribe to a plan', $page); - $page = $this->post_page('update-plan', array( + $page = $this->post_page('update-plan', [ 'plan' => 'twfy-1k', 'charitable_tick' => 'on', 'charitable' => 'c', 'charity_number' => '123456', 'tandcs_tick' => 'on', - )); + ]); $this->assertEquals('Location: /api/key?updated=1', $page); $page = $this->get_page('key', ['updated' => 1]); $this->assertStringContainsString('Your current plan is Some calls per month.', $page); diff --git a/tests/AcceptBasicTest.php b/tests/AcceptBasicTest.php index 9d5ab704ad..631b9b7df7 100644 --- a/tests/AcceptBasicTest.php +++ b/tests/AcceptBasicTest.php @@ -13,7 +13,7 @@ public function getDataSet() return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/acceptance.xml'); } - private function fetch_page($path, $file = 'index.php', $vars = array()) + private function fetch_page($path, $file = 'index.php', $vars = []) { return $this->base_fetch_page($vars, $path, $file); } @@ -44,7 +44,7 @@ public function testMPList() */ public function testLordsList() { - $page = $this->fetch_page('mps', 'index.php', array('representative_type' => 'peer')); + $page = $this->fetch_page('mps', 'index.php', ['representative_type' => 'peer']); $this->assertStringContainsString('All Members of the House of Lords', $page); $this->assertStringContainsString('Mr Current-Lord', $page); } @@ -54,7 +54,7 @@ public function testLordsList() */ public function testMSPList() { - $page = $this->fetch_page('mps', 'index.php', array('representative_type' => 'msp')); + $page = $this->fetch_page('mps', 'index.php', ['representative_type' => 'msp']); $this->assertStringContainsString('Scottish Parliament', $page); $this->assertStringContainsString('All MSPs', $page); $this->assertStringContainsString('Test Current-MSP', $page); @@ -65,7 +65,7 @@ public function testMSPList() */ public function testMLAList() { - $page = $this->fetch_page('mps', 'index.php', array('representative_type' => 'mla')); + $page = $this->fetch_page('mps', 'index.php', ['representative_type' => 'mla']); $this->assertStringContainsString('Northern Ireland Assembly', $page); $this->assertStringContainsString('All MLAs', $page); $this->assertStringContainsString('Test Current-MLA', $page); @@ -76,7 +76,7 @@ public function testMLAList() */ public function testDebatesList() { - $page = $this->fetch_page('', 'section.php', array('type' => 'debates')); + $page = $this->fetch_page('', 'section.php', ['type' => 'debates']); $this->assertStringContainsString('UK Parliament Hansard Debates', $page); $this->assertStringContainsString('Recent House of Commons debates', $page); $this->assertStringContainsString('Test Hansard Section', $page); diff --git a/tests/AlertsPageTest.php b/tests/AlertsPageTest.php index ded94576ab..d97e655667 100644 --- a/tests/AlertsPageTest.php +++ b/tests/AlertsPageTest.php @@ -20,25 +20,25 @@ private function fetch_page($vars) public function testFetchPage() { - $page = $this->fetch_page(array()); + $page = $this->fetch_page([]); $this->assertStringContainsString('TheyWorkForYou Email Alerts', $page); } public function testKeywordOnly() { - $page = $this->fetch_page(array( 'alertsearch' => 'elephant')); + $page = $this->fetch_page([ 'alertsearch' => 'elephant']); $this->assertStringContainsString('Receive alerts when [elephant] is mentioned', $page); } public function testPostCodeOnly() { - $page = $this->fetch_page(array( 'alertsearch' => 'SE17 3HE')); + $page = $this->fetch_page([ 'alertsearch' => 'SE17 3HE']); $this->assertStringContainsString('when Mrs Test Current-MP', $page); } public function testPostCodeWithKeyWord() { - $page = $this->fetch_page(array( 'alertsearch' => 'SE17 3HE elephant')); + $page = $this->fetch_page([ 'alertsearch' => 'SE17 3HE elephant']); $this->assertStringContainsString('You have used a postcode and something else', $page); $this->assertStringContainsString('Mentions of [elephant] by your MP, Mrs Test Current-MP', $page); $this->assertStringNotContainsString('by your MSP', $page); @@ -46,7 +46,7 @@ public function testPostCodeWithKeyWord() public function testScottishPostcodeWithKeyword() { - $page = $this->fetch_page(array( 'alertsearch' => 'PH6 2DB elephant')); + $page = $this->fetch_page([ 'alertsearch' => 'PH6 2DB elephant']); $this->assertStringContainsString('You have used a postcode and something else', $page); $this->assertStringContainsString('Mentions of [elephant] by your MP, Mr Test2 Current-MP', $page); $this->assertStringContainsString('Mentions of [elephant] by your MSP, Mrs Test Current-MSP', $page); @@ -54,7 +54,7 @@ public function testScottishPostcodeWithKeyword() public function testPostcodeAndKeywordWithNoSittingMP() { - $page = $this->fetch_page(array( 'alertsearch' => 'OX1 4LF elephant')); + $page = $this->fetch_page([ 'alertsearch' => 'OX1 4LF elephant']); $this->assertStringContainsString('You have used a postcode and something else', $page); $this->assertStringNotContainsString('Did you mean to get alerts for when your MP', $page); } diff --git a/tests/AlertsTest.php b/tests/AlertsTest.php index a8278f9e88..65dc7c2455 100644 --- a/tests/AlertsTest.php +++ b/tests/AlertsTest.php @@ -77,11 +77,11 @@ public function testAdd() { $ALERT = new ALERT(); - $details = array( + $details = [ 'email' => 'test@theyworkforyou.com', 'keyword' => 'test', 'pc' => 'SW1A 1AA', - ); + ]; $response = $ALERT->add($details, false, true); @@ -100,11 +100,11 @@ public function testAddExisting() { $ALERT = new ALERT(); - $details = array( + $details = [ 'email' => 'test3@theyworkforyou.com', 'keyword' => 'test3', 'pc' => 'SW1A 1AA', - ); + ]; $response = $ALERT->add($details, false, true); @@ -122,11 +122,11 @@ public function testAddDeleted() { $ALERT = new ALERT(); - $details = array( + $details = [ 'email' => 'test6@theyworkforyou.com', 'keyword' => 'test6', 'pc' => 'SW1A 1AA', - ); + ]; $response = $ALERT->add($details, false, true); @@ -170,11 +170,11 @@ public function testCheckTokenCorrect() $response = $ALERT->check_token('1::token1'); - $this->assertEquals(array( + $this->assertEquals([ 'id' => 1, 'email' => 'test@theyworkforyou.com', 'criteria' => 'test1', - ), $response); + ], $response); } /** diff --git a/tests/DivisionsTest.php b/tests/DivisionsTest.php index ce020a642d..292e7c1fbe 100644 --- a/tests/DivisionsTest.php +++ b/tests/DivisionsTest.php @@ -17,18 +17,18 @@ private function fetch_page($vars) private function fetch_division_page() { - return $this->fetch_page(array( 'pagetype' => 'divisions', 'pid' => 2, 'policy' => 363, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions' )); + return $this->fetch_page([ 'pagetype' => 'divisions', 'pid' => 2, 'policy' => 363, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions' ]); } private function fetch_mp_recent_page() { - $vars = array( 'pagetype' => 'recent', 'pid' => 2, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/recent' ); + $vars = [ 'pagetype' => 'recent', 'pid' => 2, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/recent' ]; return $this->base_fetch_page($vars, 'mp', 'index.php', '/mp/recent.php'); } private function fetch_recent_page() { - return $this->base_fetch_page(array('url' => '/divisions' ), 'divisions', 'index.php', '/divisions/index.php'); + return $this->base_fetch_page(['url' => '/divisions' ], 'divisions', 'index.php', '/divisions/index.php'); } @@ -59,14 +59,14 @@ public function testSinglePolicy() public function testMPPageContainsAgreement() { // Checks this MP contains a reference to the agreement - $page = $this->fetch_page(array( 'pagetype' => 'divisions', 'pid' => 2, 'policy' => 363, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions' )); + $page = $this->fetch_page([ 'pagetype' => 'divisions', 'pid' => 2, 'policy' => 363, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions' ]); $this->assertStringContainsString('Example Agreement', $page); } public function testMPPageDoesNotContainsAgreement() { // Checks this MP does not contain agreement - should be out of time scope - $page = $this->fetch_page(array( 'pagetype' => 'divisions', 'pid' => 6, 'policy' => 363, 'url' => '/mp/6/test_current-mp/test_westminster_constituency/divisions' )); + $page = $this->fetch_page([ 'pagetype' => 'divisions', 'pid' => 6, 'policy' => 363, 'url' => '/mp/6/test_current-mp/test_westminster_constituency/divisions' ]); $this->assertStringNotContainsString('Example Agreement', $page); $this->assertStringNotContainsString('This person has not voted on this policy', $page); @@ -141,7 +141,7 @@ public function testStrongIndicators() public function testNotEnoughInfoStatement() { - return $this->fetch_page(array( 'pagetype' => 'divisions', 'pid' => 2, 'policy' => 810, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions' )); + return $this->fetch_page([ 'pagetype' => 'divisions', 'pid' => 2, 'policy' => 810, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions' ]); $this->assertStringContainsString('we don’t have enough information to calculate Test Current-MP’s position', $page); } @@ -154,7 +154,7 @@ public function testRecentDivisionsForMP() public function testSingleDivision() { - $page = $this->base_fetch_page(array('url' => '/divisions/division.php', 'vote' => 'pw-3012-01-01-1-commons' ), 'divisions', 'division.php', '/divisions/division.php'); + $page = $this->base_fetch_page(['url' => '/divisions/division.php', 'vote' => 'pw-3012-01-01-1-commons' ], 'divisions', 'division.php', '/divisions/division.php'); $this->assertStringContainsString('A majority of MPs voted in favour of a thing', $page); $this->assertStringContainsString('Aye: 200', $page); $this->assertStringNotContainsString('No:', $page); # Summary 100, but no actual votes. In reality, summary can only be <= actual. diff --git a/tests/HansardTest.php b/tests/HansardTest.php index 70a4865897..d141601d67 100644 --- a/tests/HansardTest.php +++ b/tests/HansardTest.php @@ -45,9 +45,9 @@ public function testGetDataByPerson() { $HANSARD = new HANSARDLIST(); - $args = array( + $args = [ 'person_id' => '2', - ); + ]; $response = $HANSARD->_get_data_by_person($args); @@ -71,9 +71,9 @@ public function testGetDataByDate() $HANSARD->major = 1; $HANSARD->listpage = 'test'; - $args = array( + $args = [ 'date' => '2014-01-01', - ); + ]; $response = $HANSARD->_get_data_by_date($args); @@ -100,9 +100,9 @@ public function testGetDataByGid() $HANSARD->gidprefix = 'com.theyworkforyou/test/hansard/'; $HANSARD->listpage = 'test'; - $args = array( + $args = [ 'gid' => '3', - ); + ]; $response = $HANSARD->_get_data_by_gid($args); @@ -123,9 +123,9 @@ public function testGetItem() $HANSARD->major = 1; $HANSARD->gidprefix = 'com.theyworkforyou/test/hansard/'; - $args = array( + $args = [ 'gid' => '3', - ); + ]; $response = $HANSARD->_get_item($args); diff --git a/tests/MemberTest.php b/tests/MemberTest.php index 1b8830fdc2..2ecc4c35df 100644 --- a/tests/MemberTest.php +++ b/tests/MemberTest.php @@ -28,7 +28,7 @@ public function setUp(): void */ public function testGetMPByPersonID() { - $MEMBER = new MEMBER(array('person_id' => 2)); + $MEMBER = new MEMBER(['person_id' => 2]); $this->assertEquals(1, $MEMBER->member_id); $this->assertEquals(2, $MEMBER->person_id); @@ -39,7 +39,7 @@ public function testGetMPByPersonID() */ public function testGetMPByMemberID() { - $MEMBER = new MEMBER(array('member_id' => 1)); + $MEMBER = new MEMBER(['member_id' => 1]); $this->assertEquals(1, $MEMBER->member_id); $this->assertEquals(2, $MEMBER->person_id); @@ -53,7 +53,7 @@ public function testGetMPByName() global $this_page; $this_page = 'mp'; - $MEMBER = new MEMBER(array('name' => 'test current-mp')); + $MEMBER = new MEMBER(['name' => 'test current-mp']); $this->assertEquals(1, $MEMBER->member_id); $this->assertEquals(2, $MEMBER->person_id); @@ -64,7 +64,7 @@ public function testGetMPByName() */ public function testGetMPByConstituency() { - $MEMBER = new MEMBER(array('constituency' => 'test westminster constituency')); + $MEMBER = new MEMBER(['constituency' => 'test westminster constituency']); $this->assertEquals(1, $MEMBER->member_id); $this->assertEquals(2, $MEMBER->person_id); @@ -78,7 +78,7 @@ public function testGetMPByNameAndConstituency() global $this_page; $this_page = 'mp'; - $MEMBER = new MEMBER(array('name' => 'test current-mp', 'constituency' => 'test westminster constituency')); + $MEMBER = new MEMBER(['name' => 'test current-mp', 'constituency' => 'test westminster constituency']); $this->assertEquals(1, $MEMBER->member_id); $this->assertEquals(2, $MEMBER->person_id); @@ -93,10 +93,10 @@ public function testGetDuplicateMPsByName() $this_page = 'mp'; try { - $MEMBER = new MEMBER(array('name' => 'test duplicate-mp')); + $MEMBER = new MEMBER(['name' => 'test duplicate-mp']); } catch (MySociety\TheyWorkForYou\MemberMultipleException $e) { - $this->assertEquals(array(11 => 'Test Westminster Constituency', - 10 => 'Test Westminster Constituency'), $e->ids); + $this->assertEquals([11 => 'Test Westminster Constituency', + 10 => 'Test Westminster Constituency'], $e->ids); return; } $this->fail('Multiple member exception not raised'); @@ -107,7 +107,7 @@ public function testGetDuplicateMPsByName() */ public function testGetMPURL() { - $MEMBER = new MEMBER(array('person_id' => 2)); + $MEMBER = new MEMBER(['person_id' => 2]); $this->assertEquals('/mp/2/test_current-mp/test_westminster_constituency', $MEMBER->url()); } @@ -119,7 +119,7 @@ public function testGetMPURL() */ public function testGetMPSpecialCharacterURL() { - $MEMBER = new MEMBER(array('person_id' => 12)); + $MEMBER = new MEMBER(['person_id' => 12]); $this->assertEquals('/mp/12/test_special-character-constituency/test_constituency%2C_comma', $MEMBER->url()); } @@ -129,7 +129,7 @@ public function testGetMPSpecialCharacterURL() */ public function testGetPeerURL() { - $MEMBER = new MEMBER(array('person_id' => 3)); + $MEMBER = new MEMBER(['person_id' => 3]); $this->assertEquals('/peer/3/mr_current-lord', $MEMBER->url()); } @@ -139,7 +139,7 @@ public function testGetPeerURL() */ public function testGetMLAURL() { - $MEMBER = new MEMBER(array('person_id' => 8)); + $MEMBER = new MEMBER(['person_id' => 8]); $this->assertEquals('/mla/8/test_previous-mla', $MEMBER->url()); } @@ -149,7 +149,7 @@ public function testGetMLAURL() */ public function testGetMSPURL() { - $MEMBER = new MEMBER(array('person_id' => 5)); + $MEMBER = new MEMBER(['person_id' => 5]); $this->assertEquals('/msp/5/test_current-msp', $MEMBER->url()); } @@ -159,7 +159,7 @@ public function testGetMSPURL() */ public function testGetElizabethIIURL() { - $MEMBER = new MEMBER(array('person_id' => 13935)); + $MEMBER = new MEMBER(['person_id' => 13935]); $this->assertEquals('/royal/elizabeth_the_second', $MEMBER->url()); } @@ -169,12 +169,12 @@ public function testGetElizabethIIURL() */ public function testEnteredLeftHouseString() { - $MEMBER = new MySociety\TheyWorkForYou\Member(array('person_id' => 9)); + $MEMBER = new MySociety\TheyWorkForYou\Member(['person_id' => 9]); - $this->assertEquals(array( + $this->assertEquals([ "Entered the Scottish Parliament on 1 January 1990 — General election", "Left the Scottish Parliament on 31 December 1999 — General election", - ), $MEMBER->getEnterLeaveStrings()); + ], $MEMBER->getEnterLeaveStrings()); } /** @@ -184,7 +184,7 @@ public function testEnteredLeftHouseString() */ public function testLoadExtraInfo() { - $MEMBER = new MEMBER(array('person_id' => 16)); + $MEMBER = new MEMBER(['person_id' => 16]); $MEMBER->load_extra_info(); @@ -201,13 +201,13 @@ public function testLoadExtraInfo() $this->assertEquals('Test Constituency Value', $MEMBER->extra_info['test_constituency_key']); // Have we correctly loaded the PBC membership? - $this->assertEquals(array( + $this->assertEquals([ 'title' => 'Test Bill', 'session' => '2013-14', 'attending' => 1, 'chairman' => 1, 'outof' => 0, - ), $MEMBER->extra_info['pbc'][1]); + ], $MEMBER->extra_info['pbc'][1]); } /** @@ -218,79 +218,79 @@ public function testFindMemberImage() // A missing image with no backup should reply null/null $this->assertEquals( - array(null, null), + [null, null], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(1), ); // Missing, small, use default $this->assertEquals( - array('/images/unknownperson_large.png', 'L'), + ['/images/unknownperson_large.png', 'L'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(1, false, true), ); // Missing, large, use default Lord $this->assertEquals( - array('/images/unknownlord_large.png', 'L'), + ['/images/unknownlord_large.png', 'L'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(1, false, 'lord'), ); // Missing, small, use default $this->assertEquals( - array('/images/unknownperson.png', 'S'), + ['/images/unknownperson.png', 'S'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(1, true, true), ); // Missing, small, use default Lord $this->assertEquals( - array('/images/unknownlord.png', 'S'), + ['/images/unknownlord.png', 'S'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(1, true, 'lord'), ); // Does a large JPEG work? $this->assertEquals( - array('/images/mpsL/11132.jpeg', 'L'), + ['/images/mpsL/11132.jpeg', 'L'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(11132), ); // Does a small JPEG work? $this->assertEquals( - array('/images/mps/10001.jpeg', 'S'), + ['/images/mps/10001.jpeg', 'S'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(10001, true), ); // Does a large PNG work? No large PNGs $this->assertEquals( - array('/images/mps/13943.png', 'S'), + ['/images/mps/13943.png', 'S'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(13943), ); // Does a small PNG work? $this->assertEquals( - array('/images/mps/13943.png', 'S'), + ['/images/mps/13943.png', 'S'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(13943, true), ); // Does a large JPG work? $this->assertEquals( - array('/images/mpsL/10001.jpg', 'L'), + ['/images/mpsL/10001.jpg', 'L'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(10001), ); // Does a small JPG work? $this->assertEquals( - array('/images/mps/10552.jpg', 'S'), + ['/images/mps/10552.jpg', 'S'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(10552, true), ); // If we request one we know we have, but also say use a substitute? $this->assertEquals( - array('/images/mps/10001.jpeg', 'S'), + ['/images/mps/10001.jpeg', 'S'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(10001, true, true), ); // If we only have a small, but don't request explicitly? $this->assertEquals( - array('/images/mps/28619.jpg', 'S'), + ['/images/mps/28619.jpg', 'S'], \MySociety\TheyWorkForYou\Utility\Member::findMemberImage(28619), ); @@ -298,20 +298,20 @@ public function testFindMemberImage() public function testIsNew() { - $MEMBER = new MySociety\TheyWorkForYou\Member(array('person_id' => 17)); + $MEMBER = new MySociety\TheyWorkForYou\Member(['person_id' => 17]); $this->assertNotTrue($MEMBER->isNew()); self::$db->query("UPDATE member SET entered_house = NOW() WHERE person_id = 17"); // do this to force a reload - $MEMBER = new MySociety\TheyWorkForYou\Member(array('person_id' => 17)); + $MEMBER = new MySociety\TheyWorkForYou\Member(['person_id' => 17]); $this->assertTrue($MEMBER->isNew()); } public function testGetEntryDate() { - $MEMBER = new MySociety\TheyWorkForYou\Member(array('person_id' => 18)); + $MEMBER = new MySociety\TheyWorkForYou\Member(['person_id' => 18]); $this->assertEquals($MEMBER->getEntryDate(), '2014-05-01'); $this->assertEquals($MEMBER->getEntryDate(1), '2014-05-01'); @@ -323,44 +323,44 @@ public function testGetEntryDate() public function testGetRegionalList() { - $this->assertEquals(array(), \MySociety\TheyWorkForYou\Member::getRegionalList('', '', '')); + $this->assertEquals([], \MySociety\TheyWorkForYou\Member::getRegionalList('', '', '')); - $msps = array( - array( + $msps = [ + [ 'person_id' => "19", 'name' => "Mr Regional MSP1", 'constituency' => "Mid Scotland and Fife", 'house' => "4", - ), - array( + ], + [ 'person_id' => "20", 'name' => "Mr Regional MSP2", 'constituency' => "Mid Scotland and Fife", 'house' => "4", - ), - ); + ], + ]; $this->assertEquals($msps, \MySociety\TheyWorkForYou\Member::getRegionalList('KY16 8YG', 4, 'SPE')); - $mlas = array( - array( + $mlas = [ + [ 'person_id' => "21", 'name' => "Mr Regional MLA1", 'constituency' => "Belfast West", 'house' => "3", - ), - array( + ], + [ 'person_id' => "22", 'name' => "Mr Regional MLA2", 'constituency' => "Belfast West", 'house' => "3", - ), - ); + ], + ]; $this->assertEquals($mlas, \MySociety\TheyWorkForYou\Member::getRegionalList('BT17 0XD', 3, 'NIE')); - $this->assertEquals(array(), \MySociety\TheyWorkForYou\Member::getRegionalList('BT17 0XD', 4, 'NIE')); - $this->assertEquals(array(), \MySociety\TheyWorkForYou\Member::getRegionalList('BT17 0XD', 3, 'SPE')); - $this->assertEquals(array(), \MySociety\TheyWorkForYou\Member::getRegionalList('KY16 8YG', 3, 'SPE')); - $this->assertEquals(array(), \MySociety\TheyWorkForYou\Member::getRegionalList('KY16 8YG', 4, 'NIE')); - $this->assertEquals(array(), \MySociety\TheyWorkForYou\Member::getRegionalList('KY16 8YG', 4, '')); - $this->assertEquals(array(), \MySociety\TheyWorkForYou\Member::getRegionalList('KY16 8YG', '', '')); + $this->assertEquals([], \MySociety\TheyWorkForYou\Member::getRegionalList('BT17 0XD', 4, 'NIE')); + $this->assertEquals([], \MySociety\TheyWorkForYou\Member::getRegionalList('BT17 0XD', 3, 'SPE')); + $this->assertEquals([], \MySociety\TheyWorkForYou\Member::getRegionalList('KY16 8YG', 3, 'SPE')); + $this->assertEquals([], \MySociety\TheyWorkForYou\Member::getRegionalList('KY16 8YG', 4, 'NIE')); + $this->assertEquals([], \MySociety\TheyWorkForYou\Member::getRegionalList('KY16 8YG', 4, '')); + $this->assertEquals([], \MySociety\TheyWorkForYou\Member::getRegionalList('KY16 8YG', '', '')); } } diff --git a/tests/PageTest.php b/tests/PageTest.php index c1bcf35884..65fef2a33f 100644 --- a/tests/PageTest.php +++ b/tests/PageTest.php @@ -20,14 +20,14 @@ private function fetch_page($vars) public function testQueenie() { - $page = $this->fetch_page(array( 'representative_type' => 'royal', 'n' => 'elizabeth_the_second' )); + $page = $this->fetch_page([ 'representative_type' => 'royal', 'n' => 'elizabeth_the_second' ]); $this->assertStringContainsString('Elizabeth the Second', $page); $this->assertStringContainsString('Coronated on 2 June 1953', $page); } public function testSittingMP() { - $page = $this->fetch_page(array( 'pid' => 2, 'url' => '/mp/2/test_current-mp/test_westminster_constituency' )); + $page = $this->fetch_page([ 'pid' => 2, 'url' => '/mp/2/test_current-mp/test_westminster_constituency' ]); $this->assertStringContainsString('Test Current-MP', $page); $this->assertMatchesRegularExpression('#\s*Test Westminster Constituency\s*#', $page); $this->assertMatchesRegularExpression('#\s*Labour\s*MP\s*#', $page); @@ -35,7 +35,7 @@ public function testSittingMP() public function testSittingMLA() { - $page = $this->fetch_page(array( 'pid' => 4, 'representative_type' => 'mla', 'url' => '/mp/4/test_current-mla' )); + $page = $this->fetch_page([ 'pid' => 4, 'representative_type' => 'mla', 'url' => '/mp/4/test_current-mla' ]); $this->assertStringContainsString('Test Current-MLA', $page); $this->assertMatchesRegularExpression('#\s*Test Northern Ireland Constituency\s*#', $page); $this->assertMatchesRegularExpression('#\s*Sinn Féin\s*MLA\s*#', $page); @@ -46,7 +46,7 @@ public function testSittingMLA() */ public function testSittingSinnFeinMP() { - $page = $this->fetch_page(array( 'pid' => 15, 'url' => '/mp/15/test_current-sf-mp/test_westminster_constituency' )); + $page = $this->fetch_page([ 'pid' => 15, 'url' => '/mp/15/test_current-sf-mp/test_westminster_constituency' ]); $this->assertStringContainsString('Sinn Féin MPs do not take their seats in Parliament.', $page); } @@ -55,7 +55,7 @@ public function testSittingSinnFeinMP() */ public function testSittingNonSinnFeinMP() { - $page = $this->fetch_page(array( 'pid' => 2, 'url' => '/mp/2/test_current-mp/test_westminster_constituency' )); + $page = $this->fetch_page([ 'pid' => 2, 'url' => '/mp/2/test_current-mp/test_westminster_constituency' ]); $this->assertStringNotContainsString('Sinn Féin MPs do not take their seats in Parliament.', $page); } @@ -64,7 +64,7 @@ public function testSittingNonSinnFeinMP() */ public function testSpeaker() { - $page = $this->fetch_page(array( 'pid' => 13, 'url' => '/mp/13/test_speaker/buckingham' )); + $page = $this->fetch_page([ 'pid' => 13, 'url' => '/mp/13/test_speaker/buckingham' ]); $this->assertMatchesRegularExpression('#\s*Speaker\s*MP\s*#', $page); } @@ -75,7 +75,7 @@ public function testBanner() # makes sure it is empty in case there's something hanging # about in memcached $banner->set_text('', "banner"); - $page = $this->fetch_page(array( 'url' => '/' )); + $page = $this->fetch_page([ 'url' => '/' ]); $this->assertStringNotContainsString('