Skip to content

Commit

Permalink
[REF] Remove duplicate checks for an array key existing
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Apr 13, 2020
1 parent 9a05c57 commit 2cfe2cf
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 41 deletions.
15 changes: 6 additions & 9 deletions CRM/Contact/Form/Edit/CustomData.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,13 @@ public static function preProcess(&$form) {
* Reference to the form object.
*/
public static function buildQuickForm(&$form) {
if (!empty($form->_submitValues)) {
if ($customValueCount = CRM_Utils_Array::value('hidden_custom_group_count', $form->_submitValues)) {
if (is_array($customValueCount)) {
if (array_key_exists(0, $customValueCount)) {
unset($customValueCount[0]);
}
$form->_customValueCount = $customValueCount;
$form->assign('customValueCount', $customValueCount);
}
$customValueCount = $form->_submitValues['hidden_custom_group_count'] ?? NULL;
if (is_array($customValueCount)) {
if (array_key_exists(0, $customValueCount)) {
unset($customValueCount[0]);
}
$form->_customValueCount = $customValueCount;
$form->assign('customValueCount', $customValueCount);
}
CRM_Custom_Form_CustomData::buildQuickForm($form);

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Page/Inline/CommunicationPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function run() {
$communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id');
if (!empty($communicationStyle)) {
if (!empty($defaults['communication_style_id'])) {
$defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array::value('communication_style_id', $defaults)];
$defaults['communication_style_display'] = $communicationStyle[$defaults['communication_style_id']];
}
else {
// Make sure the field is displayed as long as it is active, even if it is unset for this contact.
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Page/Inline/Demographics.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function run() {

if (!empty($defaults['gender_id'])) {
$gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
$defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)];
$defaults['gender_display'] = $gender[$defaults['gender_id']];
}
$this->assignFieldMetadataToTemplate('Contact');

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Page/View/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function view() {
$communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id');
if (!empty($communicationStyle)) {
if (!empty($defaults['communication_style_id'])) {
$defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array::value('communication_style_id', $defaults)];
$defaults['communication_style_display'] = $communicationStyle[$defaults['communication_style_id']];
}
else {
// Make sure the field is displayed as long as it is active, even if it is unset for this contact.
Expand Down
6 changes: 3 additions & 3 deletions CRM/Contact/Page/View/Vcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function run() {
}

if (!empty($defaults['birth_date'])) {
$vcard->setBirthday(CRM_Utils_Array::value('birth_date', $defaults));
$vcard->setBirthday($defaults['birth_date']);
}

if (!empty($defaults['home_URL'])) {
Expand All @@ -98,11 +98,11 @@ public function run() {
$locality = $location['city'] ?? NULL;
$region = NULL;
if (!empty($location['state_province_id'])) {
$region = $stateProvices[CRM_Utils_Array::value('state_province_id', $location)];
$region = $stateProvices[$location['state_province_id']];
}
$country = NULL;
if (!empty($location['country_id'])) {
$country = $countries[CRM_Utils_Array::value('country_id', $location)];
$country = $countries[$location['country_id']];
}

$postcode = $location['postal_code'] ?? NULL;
Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/BAO/ContributionSoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public static function formatHonoreeProfileFields($form, $params, $honorId = NUL
switch ($profileContactType) {
case 'Individual':
if (array_key_exists('prefix_id', $params)) {
$honorName = CRM_Utils_Array::value(CRM_Utils_Array::value('prefix_id', $params),
$honorName = CRM_Utils_Array::value($params['prefix_id'],
CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id')
);
unset($profileFields['prefix_id']);
Expand All @@ -571,7 +571,7 @@ public static function formatHonoreeProfileFields($form, $params, $honorId = NUL
unset($profileFields['first_name']);
unset($profileFields['last_name']);
if (array_key_exists('suffix_id', $params)) {
$honorName .= ' ' . CRM_Utils_Array::value(CRM_Utils_Array::value('suffix_id', $params),
$honorName .= ' ' . CRM_Utils_Array::value($params['suffix_id'],
CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id')
);
unset($profileFields['suffix_id']);
Expand Down
6 changes: 3 additions & 3 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function handlePledge(&$form, $params, $contributionParams, $pledg
}
$pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
if (!empty($params['start_date'])) {
$pledgeParams['frequency_day'] = intval(date("d", strtotime(CRM_Utils_Array::value('start_date', $params))));
$pledgeParams['frequency_day'] = intval(date("d", strtotime($params['start_date'])));
$pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date('Ymd', strtotime(CRM_Utils_Array::value('start_date', $params)));
}
$pledgeParams['status_id'] = $contribution->contribution_status_id;
Expand Down Expand Up @@ -947,10 +947,10 @@ public static function processFormContribution(
foreach ($lineItemValue as $key => $value) {
if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
if (isset($dataArray[$value['tax_rate']])) {
$dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
$dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + $value['tax_amount'];
}
else {
$dataArray[$value['tax_rate']] = $value['tax_amount'] ?? NULL;
$dataArray[$value['tax_rate']] = $value['tax_amount'];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionView.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function preProcess() {

// show billing address location details, if exists
if (!empty($values['address_id'])) {
$addressParams = ['id' => CRM_Utils_Array::value('address_id', $values)];
$addressParams = ['id' => $values['address_id']];
$addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
$addressDetails = array_values($addressDetails);
$values['billing_address'] = $addressDetails[0]['display'];
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/BAO/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public static function create(&$params, $fixAddress = TRUE, $entity = NULL) {

$addressExists = self::dataExists($value);
if (empty($value['id'])) {
if (!empty($addresses) && array_key_exists(CRM_Utils_Array::value('location_type_id', $value), $addresses)) {
$value['id'] = $addresses[CRM_Utils_Array::value('location_type_id', $value)];
if (!empty($addresses) && !empty($value['location_type_id']) && array_key_exists($value['location_type_id'], $addresses)) {
$value['id'] = $addresses[$value['location_type_id']];
}
}

Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/BAO/UFJoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function findJoinEntryId(&$params) {

// CRM-4377 (ab)uses the module column
if (isset($params['module'])) {
$dao->module = $params['module'] ?? NULL;
$dao->module = $params['module'];
}
$dao->entity_table = $params['entity_table'] ?? NULL;
$dao->entity_id = $params['entity_id'] ?? NULL;
Expand Down Expand Up @@ -143,7 +143,7 @@ public static function getUFGroupIds(&$params) {

// CRM-4377 (ab)uses the module column
if (isset($params['module'])) {
$dao->module = $params['module'] ?? NULL;
$dao->module = $params['module'];
}
$dao->entity_table = $params['entity_table'] ?? NULL;
$dao->entity_id = $params['entity_id'] ?? NULL;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/Registration/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ public static function fixLocationFields(&$params, &$fields, &$form) {

// Add the billing names to the billing address, if a billing name is set
if (!empty($params['billing_first_name'])) {
$params["address_name-{$form->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
$params["address_name-{$form->_bltID}"] = $params['billing_first_name'] . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
$fields["address_name-{$form->_bltID}"] = 1;
}

Expand Down
4 changes: 2 additions & 2 deletions CRM/Report/BAO/ReportInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ public static function add(&$params) {
*/
public static function &create(&$params) {
if (isset($params['report_header'])) {
$params['header'] = $params['report_header'] ?? NULL;
$params['header'] = $params['report_header'];
}
if (isset($params['report_footer'])) {
$params['footer'] = $params['report_footer'] ?? NULL;
$params['footer'] = $params['report_footer'];
}

// build navigation parameters
Expand Down
9 changes: 3 additions & 6 deletions CRM/Report/Form/Grant/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,15 @@ public function alterDisplay(&$rows) {
}

if (array_key_exists('civicrm_worldregion_name', $values)) {
$region = $values['civicrm_worldregion_name'] ?? NULL;
$region = ($region) ? $region : 'Unassigned';
$region = $values['civicrm_worldregion_name'] ?: 'Unassigned';
$grantStatistics['civicrm_worldregion_name']['title'] = ts('By Region');
self::getStatistics($grantStatistics['civicrm_worldregion_name'], $region, $values,
$awardedGrants, $awardedGrantsAmount
);
}

if (array_key_exists('civicrm_address_country_id', $values)) {
$country = $countries[$values['civicrm_address_country_id']] ?? NULL;
$country = ($country) ? $country : 'Unassigned';
$country = $countries[$values['civicrm_address_country_id']] ?? 'Unassigned';
$grantStatistics['civicrm_address_country_id']['title'] = ts('By Country');
self::getStatistics($grantStatistics['civicrm_address_country_id'], $country, $values,
$awardedGrants, $awardedGrantsAmount
Expand All @@ -414,8 +412,7 @@ public function alterDisplay(&$rows) {
}

if (array_key_exists('civicrm_contact_gender_id', $values)) {
$genderLabel = $gender[$values['civicrm_contact_gender_id']] ?? NULL;
$genderLabel = ($genderLabel) ? $genderLabel : 'Unassigned';
$genderLabel = $gender[$values['civicrm_contact_gender_id']] ?? 'Unassigned';
$grantStatistics['civicrm_contact_gender_id']['title'] = ts('By Gender');
self::getStatistics($grantStatistics['civicrm_contact_gender_id'], $genderLabel, $values,
$awardedGrants, $awardedGrantsAmount
Expand Down
2 changes: 1 addition & 1 deletion api/v3/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ function civicrm_api3_contact_getquick($params) {
// Contact's based of relationhip type
$relType = NULL;
if (!empty($params['rel'])) {
$relation = explode('_', CRM_Utils_Array::value('rel', $params));
$relation = explode('_', $params['rel']);
$relType = CRM_Utils_Type::escape($relation[0], 'Integer');
$rel = CRM_Utils_Type::escape($relation[2], 'String');
}
Expand Down
8 changes: 2 additions & 6 deletions extern/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@

// To keep backward compatibility for URLs generated
// by CiviCRM < 1.7, we check for the q variable as well.
if (isset($_GET['qid'])) {
$queue_id = $_GET['qid'] ?? NULL;
}
else {
$queue_id = $_GET['q'] ?? NULL;
}
$queue_id = $_GET['qid'] ?? $_GET['q'] ?? NULL;

$url_id = $_GET['u'] ?? NULL;

if (!$url_id) {
Expand Down

0 comments on commit 2cfe2cf

Please sign in to comment.