Skip to content

Commit

Permalink
Apply @PHP74Migration rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons committed Sep 25, 2024
1 parent 96e7e1a commit b9b3117
Show file tree
Hide file tree
Showing 258 changed files with 3,986 additions and 4,018 deletions.
46 changes: 23 additions & 23 deletions classes/AlertView/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -121,31 +121,31 @@ 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
WHERE email = :email
AND criteria LIKE :criteria
AND confirmed = 1
AND deleted = 0",
array(
[
':email' => $existing['email'],
':criteria' => '%speaker:' . $old_mp_id . '%',
),
],
);

foreach ($q as $row) {
// need to reset this otherwise delete does not work
$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;
}
Expand All @@ -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)
Expand All @@ -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;
Expand Down
28 changes: 14 additions & 14 deletions classes/AlertView/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -166,26 +166,26 @@ 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']);
$this->data['alertsearch'] = '';
}

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
Expand Down Expand Up @@ -254,7 +254,7 @@ private function formatSearchTerms()

private function checkForCommonMistakes()
{
$mistakes = array();
$mistakes = [];
if (strstr($this->data['alertsearch'], ',') > -1) {
$mistakes['multiple'] = 1;
}
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions classes/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public function set_section()
public function page_metadata($page, $key)
{
return $this->getMetadata(
array(
[
'page' => $page,
'key' => $key,
),
],
'page',
);
}
Expand All @@ -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',
);
}
Expand All @@ -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]);
}

/**
Expand All @@ -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]);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions classes/Db/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions classes/Dissolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
);
];
}
}
Loading

0 comments on commit b9b3117

Please sign in to comment.