Commit 2e2c7a9a authored by mattwire's avatar mattwire
Browse files

Switch to short array syntax and remove support for CiviCRM < 5.13

parent 2225ecad
......@@ -28,7 +28,7 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
'text',
'server',
ts('Server URL'),
array('size' => 50),
['size' => 50],
true
);
......@@ -37,7 +37,7 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
'text',
'api_key',
ts('API Key'),
array('size' => 50),
['size' => 50],
false
);
......@@ -46,7 +46,7 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
'text',
'serial_number',
ts('Serial Number'),
array('size' => 20),
['size' => 20],
false
);
......@@ -55,7 +55,7 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
'text',
'username',
ts('Username'),
array('size' => 20),
['size' => 20],
false
);
......@@ -64,7 +64,7 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
'text',
'password',
ts('Password'),
array('size' => 20),
['size' => 20],
false
);
......@@ -75,20 +75,20 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
ts('Location Types'),
$locationTypes,
NULL, NULL, NULL, NULL,
array('&nbsp;&nbsp;')
['&nbsp;&nbsp;']
);
$this->addButtons(array(
array(
$this->addButtons([
[
'type' => 'submit',
'name' => ts('Submit'),
'isDefault' => TRUE,
),
));
],
]);
$this->setDefaults($settingsArray);
$this->addFormRule( array( 'CRM_Civicrmpostcodelookup_Form_Setting', 'formRule' ) );
$this->addFormRule( ['CRM_Civicrmpostcodelookup_Form_Setting', 'formRule']);
// export form elements
$this->assign('elementNames', $this->getRenderableElementNames());
......@@ -97,7 +97,7 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
static function formRule( $values ){
$errors = array();
$errors = [];
// Server is mandatory fo AFD and CiviPostcode. Server URL is in QAS lib for Experian
if ($values['provider'] == 'afd' || $values['provider'] == 'civipostcode' || $values['provider'] == 'postcodeanywhere') {
......@@ -159,7 +159,7 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
function postProcess() {
$values = $this->exportValues();
$settingsArray = array();
$settingsArray = [];
$settingsArray['provider'] = $values['provider'];
// AFD
......@@ -211,9 +211,9 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
}
function getProviderOptions() {
$options = array(
$options = [
'' => ts('- select -'),
) + $GLOBALS["providers"];
] + $GLOBALS["providers"];
return $options;
}
......@@ -228,7 +228,7 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
// auto-rendered in the loop -- such as "qfKey" and "buttons". These
// items don't have labels. We'll identify renderable by filtering on
// the 'label'.
$elementNames = array();
$elementNames = [];
foreach ($this->_elements as $element) {
/** @var HTML_QuickForm_Element $element */
$label = $element->getLabel();
......
......@@ -63,21 +63,13 @@ class CRM_Civicrmpostcodelookup_Page_Afd extends CRM_Civicrmpostcodelookup_Page_
##Close the XML source##
fclose($filetoparse);
// Check CiviCRM version & return result as appropriate
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
if ($civiVersion < 4.5) {
foreach ($addresslist as $key => $val) {
echo "{$val['label']}|{$val['id']}\n";
}
} else {
echo json_encode($addresslist);
}
echo json_encode($addresslist);
exit;
}
private static function getAddressList($simpleXMLData, $postcode) {
$addressList = array();
$addressRow = array();
$addressList = [];
$addressRow = [];
$AddressListItem = $simpleXMLData->AddressListItem;
foreach ($AddressListItem as $key => $addressItem) {
$addressRow["id"] = (string) $addressItem->PostKey;
......@@ -101,9 +93,9 @@ class CRM_Civicrmpostcodelookup_Page_Afd extends CRM_Civicrmpostcodelookup_Page_
}
$address = self::getAddressByMoniker($moniker);
$response = array(
$response = [
'address' => $address
);
];
echo json_encode($response);
exit;
......@@ -122,7 +114,7 @@ class CRM_Civicrmpostcodelookup_Page_Afd extends CRM_Civicrmpostcodelookup_Page_
$data = stream_get_contents($filetoparse);
$simpleXMLData = simplexml_load_string($data);
$address = array('id' => $moniker);
$address = ['id' => $moniker];
$addressItem = (array) $simpleXMLData->Address;
$address["street"] = empty($addressItem['Street']) ? '':$addressItem['Street'];
......
......@@ -70,21 +70,13 @@ class CRM_Civicrmpostcodelookup_Page_Civipostcode extends CRM_Civicrmpostcodeloo
##Close the JSON source##
fclose($filetoparse);
// Check CiviCRM version & return result as appropriate
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
if ($civiVersion < 4.5) {
foreach ($addresslist as $key => $val) {
echo "{$val['label']}|{$val['id']}\n";
}
} else {
echo json_encode($addresslist);
}
echo json_encode($addresslist);
exit;
}
private static function getAddressList($simpleJSONData, $postcode) {
$addressList = array();
$addressRow = array();
$addressList = [];
$addressRow = [];
$AddressListItem = $simpleJSONData->results;
foreach ($AddressListItem as $key => $addressItem) {
$addressLineArray = self::formatAddressLines($addressItem, TRUE);
......@@ -116,9 +108,9 @@ class CRM_Civicrmpostcodelookup_Page_Civipostcode extends CRM_Civicrmpostcodeloo
}
$address = self::getAddressByMoniker($moniker);
$response = array(
$response = [
'address' => $address
);
];
echo json_encode($response);
exit;
......@@ -173,7 +165,7 @@ class CRM_Civicrmpostcodelookup_Page_Civipostcode extends CRM_Civicrmpostcodeloo
$addressLines = $addressLineObj->getAddressLines();
if ($forList == FALSE) {
$address = array('id' => $addressObj->id);
$address = ['id' => $addressObj->id];
}
if (!empty($addressLines[0])) {
......
......@@ -9,7 +9,7 @@ class CRM_PostcodeLookup_Page_Ajax extends CRM_Civicrmpostcodelookup_Page_Postco
static private $qacampture;
public static function getQasCredentials($account_type) {
$credentials = array();
$credentials = [];
$settingsStr = CRM_Core_BAO_Setting::getItem('CiviCRM Postcode Lookup', 'api_details');
$settingsArray = unserialize($settingsStr);
......@@ -52,13 +52,13 @@ class CRM_PostcodeLookup_Page_Ajax extends CRM_Civicrmpostcodelookup_Page_Postco
$qaCapture = self::getQACapture();
$ret = $qaCapture->Search("$number, $postcode", 'GBR', 'Singleline', true);//, $intensity, $promptset, $threshold, $timeout, $layout, $formattedAddressInPicklist, $requestTag, $localisation)
$response = array();
$response['items'] = array();
$response = [];
$response['items'] = [];
foreach($ret->Picklist->Items as $item) {
$response['items'][] = array(
$response['items'][] = [
'id' => $item->Moniker,
'label' => $item->PartialAddress,
);
];
}
//mzeman: get the address details if it's the precise one
......@@ -69,16 +69,7 @@ class CRM_PostcodeLookup_Page_Ajax extends CRM_Civicrmpostcodelookup_Page_Postco
$response['address'] = $address;
}
// Check CiviCRM version & return result as appropriate
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
if ($civiVersion < 4.5) {
foreach ($response as $key => $val) {
echo "{$val['label']}|{$val['id']}\n";
}
} else {
echo json_encode($response);
}
echo json_encode($response);
exit;
}
......@@ -89,9 +80,9 @@ class CRM_PostcodeLookup_Page_Ajax extends CRM_Civicrmpostcodelookup_Page_Postco
}
$address = self::getAddressByMoniker($moniker);
$response = array(
$response = [
'address' => $address
);
];
echo json_encode($response);
exit;
......@@ -114,7 +105,7 @@ class CRM_PostcodeLookup_Page_Ajax extends CRM_Civicrmpostcodelookup_Page_Postco
private static function getAddressByMoniker($moniker) {
$addressRet = self::getQACapture()->GetAddress($moniker);
$address = array('id' => $moniker);
$address = ['id' => $moniker];
$lineCounter = 0;
foreach($addressRet->AddressLines as $line) {
switch($line->Label) {
......
......@@ -3,7 +3,7 @@
class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodelookup_Page_Postcode {
public static function isValidPostcode($postcode) {
if (in_array($postcode, array('XX200X', 'XX404X', 'XX400X', 'XX401X', 'XX429X', 'XX500X'))) {
if (in_array($postcode, ['XX200X', 'XX404X', 'XX400X', 'XX401X', 'XX429X', 'XX500X'])) {
// A getAddressIo test postcode
return TRUE;
}
......@@ -23,7 +23,7 @@ class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodeloo
// get address result from getAddress.io
$addressData = self::addressAPIResult($apiUrl);
$addresslist = array();
$addresslist = [];
if ($addressData['is_error']) {
$addresslist[0]['value'] = '';
$addresslist[0]['label'] = CRM_Utils_Array::value('Message', $addressData, 'Error in fetching address');
......@@ -31,15 +31,7 @@ class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodeloo
$addresslist = self::getAddressList($addressData, $postcode);
}
// Check CiviCRM version & return result as appropriate
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
if ($civiVersion < 4.5) {
foreach ($addresslist as $key => $val) {
echo "{$val['label']}|{$val['id']}\n";
}
} else {
echo json_encode($addresslist);
}
echo json_encode($addresslist);
exit;
}
......@@ -62,9 +54,9 @@ class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodeloo
// get address result from getAddress.io
$addressData = self::addressAPIResult($apiUrl);
$addresslist = array();
$addresslist = [];
if ($addressData['is_error']) {
$address = array();
$address = [];
} else {
$addressItems = $addressData['addresses'];
......@@ -76,9 +68,9 @@ class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodeloo
$address['postcode'] = $postcode;
}
$response = array(
$response = [
'address' => $address
);
];
echo json_encode($response);
exit;
......@@ -123,7 +115,7 @@ class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodeloo
* @return array
*/
private static function addressAPIResult($apiUrl) {
$addressData = array();
$addressData = [];
if (empty($apiUrl)) {
$addressData['is_error'] = 1;
......@@ -133,11 +125,11 @@ class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodeloo
// Get the Address Data
$curlSession = curl_init();
curl_setopt_array($curlSession, array(
curl_setopt_array($curlSession, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $apiUrl,
CURLOPT_USERAGENT => 'CiviCRM'
));
]);
$result = curl_exec($curlSession);
$header = curl_getinfo($curlSession);
......@@ -190,8 +182,8 @@ class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodeloo
* @return array
*/
private static function getAddressList($addressData, $postcode) {
$addressList = array();
$addressRow = array();
$addressList = [];
$addressRow = [];
// return, if adddressData/postcode is empty
if (empty($addressData) || empty($postcode)) {
......@@ -236,7 +228,7 @@ class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodeloo
$addressLines = explode(', ', $addressItem);
if ($forList == FALSE) {
$address = array('id' => $addressId);
$address = ['id' => $addressId];
}
if (!empty($addressLines[0])) {
$address["street_address"] = $addressLines[0];
......
......@@ -54,21 +54,13 @@ class CRM_Civicrmpostcodelookup_Page_PostcodeAnywhere extends CRM_Civicrmpostcod
$addresslist = self::getAddressList($simpleXMLData, $postcode);
}
// Check CiviCRM version & return result as appropriate
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
if ($civiVersion < 4.5) {
foreach ($addresslist as $key => $val) {
echo "{$val['label']}|{$val['id']}\n";
}
} else {
echo json_encode($addresslist);
}
echo json_encode($addresslist);
exit;
}
private static function getAddressList($simpleXMLData, $postcode) {
$addressList = array();
$addressRow = array();
$addressList = [];
$addressRow = [];
$AddressListItem = (array) $simpleXMLData->Rows;
$AddressListItems = $AddressListItem['Row'];
......@@ -103,9 +95,9 @@ class CRM_Civicrmpostcodelookup_Page_PostcodeAnywhere extends CRM_Civicrmpostcod
}
$address = self::getAddressByMoniker($moniker);
$response = array(
$response = [
'address' => $address
);
];
echo json_encode($response);
exit;
......@@ -122,7 +114,7 @@ class CRM_Civicrmpostcodelookup_Page_PostcodeAnywhere extends CRM_Civicrmpostcod
//Make the request to Postcode Anywhere and parse the XML returned
$simpleXMLData = simplexml_load_file($querystring);
$address = array('id' => $moniker);
$address = ['id' => $moniker];
$addressItemRow = (array) $simpleXMLData->Rows;
$addressItem = (array) $addressItemRow['Row'];
......
......@@ -50,7 +50,7 @@ class CRM_Civicrmpostcodelookup_Utils {
for($row = 0; $row < $rows; $row++) {
$label = $a_json[$row]["label"];
$a_label_match = array();
$a_label_match = [];
for($i = 0; $i < $p; $i++) {
......@@ -103,14 +103,4 @@ class CRM_Civicrmpostcodelookup_Utils {
return $a_json;
}
/*
* Get CiviCRM version using SQL
* Using function to get version is not compatible with all versions
*/
public static function getCiviVersion() {
$sql = "SELECT version FROM civicrm_domain";
$dao = CRM_Core_DAO::executeQuery($sql);
$dao->fetch();
return $dao->version;
}
}
......@@ -37,7 +37,7 @@ class Address
protected $addressLines = null;
protected $assembleDebugFlags = array();
protected $assembleDebugFlags = [];
public function __construct()
......@@ -398,10 +398,10 @@ class Address
*/
protected function assembleAddressLines()
{
$this->assembleDebugFlags = array('errors' => array());
$this->assembleDebugFlags = ['errors' => []];
$processed = false;
$processingError = false;
$addressLines = array();
$addressLines = [];
// Take copies of the building name and number
// This allows us to manipulate their values (specifically for the split building name rules)
......@@ -413,7 +413,7 @@ class Address
}
// Exception 4 regex: Any of the specified prefixes followed by either a number with an alpha suffix or a numeric range
$specialPrefixes = array(
$specialPrefixes = [
'Back of',
'Block',
'Blocks',
......@@ -429,7 +429,7 @@ class Address
'Suites',
'Unit',
'Units',
);
];
$ex4Regex = '/^(' . join('|', $specialPrefixes) . ')\s([0-9]+[a-zA-Z]+|[0-9]+\-[0-9]+|[a-zA-Z])$/';
if (strlen($buildingName)) {
......
......@@ -24,9 +24,9 @@ class CRM_Civicrmpostcodelookup_ExtensionUtil {
* Translated text.
* @see ts
*/
public static function ts($text, $params = array()) {
public static function ts($text, $params = []) {
if (!array_key_exists('domain', $params)) {
$params['domain'] = array(self::LONG_NAME, NULL);
$params['domain'] = [self::LONG_NAME, NULL];
}
return ts($text, $params);
}
......@@ -100,7 +100,7 @@ function _civicrmpostcodelookup_civix_civicrm_config(&$config = NULL) {
array_unshift($template->template_dir, $extDir);
}
else {
$template->template_dir = array($extDir, $template->template_dir);
$template->template_dir = [$extDir, $template->template_dir];
}
$include_path = $extRoot . PATH_SEPARATOR . get_include_path();
......@@ -140,7 +140,7 @@ function _civicrmpostcodelookup_civix_civicrm_install() {
function _civicrmpostcodelookup_civix_civicrm_postInstall() {
_civicrmpostcodelookup_civix_civicrm_config();
if ($upgrader = _civicrmpostcodelookup_civix_upgrader()) {
if (is_callable(array($upgrader, 'onPostInstall'))) {
if (is_callable([$upgrader, 'onPostInstall'])) {
$upgrader->onPostInstall();
}
}
......@@ -166,7 +166,7 @@ function _civicrmpostcodelookup_civix_civicrm_uninstall() {
function _civicrmpostcodelookup_civix_civicrm_enable() {
_civicrmpostcodelookup_civix_civicrm_config();
if ($upgrader = _civicrmpostcodelookup_civix_upgrader()) {
if (is_callable(array($upgrader, 'onEnable'))) {
if (is_callable([$upgrader, 'onEnable'])) {
$upgrader->onEnable();
}
}
......@@ -181,7 +181,7 @@ function _civicrmpostcodelookup_civix_civicrm_enable() {
function _civicrmpostcodelookup_civix_civicrm_disable() {
_civicrmpostcodelookup_civix_civicrm_config();
if ($upgrader = _civicrmpostcodelookup_civix_upgrader()) {
if (is_callable(array($upgrader, 'onDisable'))) {
if (is_callable([$upgrader, 'onDisable'])) {
$upgrader->onDisable();
}
}
......@@ -227,12 +227,12 @@ function _civicrmpostcodelookup_civix_upgrader() {
* @return array(string)
*/
function _civicrmpostcodelookup_civix_find_files($dir, $pattern) {
if (is_callable(array('CRM_Utils_File', 'findFiles'))) {
if (is_callable(['CRM_Utils_File', 'findFiles'])) {
return CRM_Utils_File::findFiles($dir, $pattern);
}
$todos = array($dir);
$result = array();
$todos = [$dir];
$result = [];
while (!empty($todos)) {
$subdir = array_shift($todos);
foreach (_civicrmpostcodelookup_civix_glob("$subdir/$pattern") as $match) {
......@@ -299,11 +299,11 @@ function _civicrmpostcodelookup_civix_civicrm_caseTypes(&$caseTypes) {
CRM_Core_Error::fatal($errorMessage);
// throw new CRM_Core_Exception($errorMessage);
}
$caseTypes[$name] = array(
$caseTypes[$name] = [
'module' => E::LONG_NAME,
'name' => $name,
'file' => $file,
);
];
}
}
......@@ -346,7 +346,7 @@ function _civicrmpostcodelookup_civix_civicrm_angularModules(&$angularModules) {
*/
function _civicrmpostcodelookup_civix_glob($pattern) {
$result = glob($pattern);
return is_array($result) ? $result : array();
return is_array($result) ? $result : [];
}
/**
......@@ -361,12 +361,12 @@ function _civicrmpostcodelookup_civix_glob($pattern) {
function _civicrmpostcodelookup_civix_insert_navigation_menu(&$menu, $path, $item) {
// If we are done going down the path, insert menu
if (empty($path)) {
$menu[] = array(
'attributes' => array_merge(array(
$menu[] = [
'attributes' => array_merge([
'label' => CRM_Utils_Array::value('name', $item),
'active' => 1,
), $item),
);
], $item),
];
return TRUE;
}
else {
......@@ -377,7 +377,7 @@ function _civicrmpostcodelookup_civix_insert_navigation_menu(&$menu, $path, $ite
foreach ($menu as $key => &$entry) {
if ($entry['attributes']['name'] == $first) {
if (!isset($entry['child'])) {
$entry['child'] = array();
$entry['child'] = [];
}
$found = _civicrmpostcodelookup_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key);
}
......@@ -390,7 +390,7 @@ function _civicrmpostcodelookup_civix_insert_navigation_menu(&$menu, $path, $ite
* (Delegated) Implements hook_civicrm_navigationMenu().
*/
function _civicrmpostcodelookup_civix_navigationMenu(&$nodes) {
if (!is_callable(array('CRM_Core_BAO_Navigation', 'fixNavigationMenu'))) {
if (!is_callable(['CRM_Core_BAO_Navigation', 'fixNavigationMenu'])) {
_civicrmpostcodelookup_civix_fixNavigationMenu($nodes);
}
}
......@@ -456,6 +456,6 @@ function _civicrmpostcodelookup_civix_civicrm_alterSettingsFolders(&$metaDataFol
*/
function _civicrmpostcodelookup_civix_civicrm_entityTypes(&$entityTypes) {
$entityTypes = array_merge($entityTypes, array (
));
$entityTypes = array_merge($entityTypes, [
]);
}
<?php
require_once 'civicrmpostcodelookup.civix.php';
use CRM_Civigiftaid_ExtensionUtil as E;
use CRM_Civicrmpostcodelookup_ExtensionUtil as E;
// Postcode lookup providers
// FIXME: Move this list to option values
......@@ -159,10 +159,6 @@ function civicrmpostcodelookup_civicrm_buildForm($formName, &$form) {
$form->assign('civiPostCodeLookupLocationTypeJson', json_encode($settingsArray['location_type_id']));
}
// Get CiviCRM version
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
$form->assign('civiVersion', $civiVersion);
CRM_Core_Resources::singleton()