Skip to content

Commit

Permalink
Swap CRM_Utils_Array::value for empty() or isset() in conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Aug 9, 2019
1 parent 3465210 commit eb17a31
Show file tree
Hide file tree
Showing 44 changed files with 73 additions and 75 deletions.
4 changes: 2 additions & 2 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ public static function create(&$params) {
}

// Set priority to Normal for Auto-populated activities (for Cases)
if (CRM_Utils_Array::value('priority_id', $params) === NULL &&
if (!isset($params['priority_id']) &&
// if not set and not 0
!CRM_Utils_Array::value('id', $params)
empty($params['id'])
) {
$priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id');
$params['priority_id'] = array_search('Normal', $priority);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Form/Extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function postProcess() {
'version' => 3,
'key' => $this->_key,
]);
if (!CRM_Utils_Array::value('is_error', $result, FALSE)) {
if (empty($result['is_error'])) {
CRM_Core_Session::setStatus("", ts('Extension Upgraded'), "success");
}
else {
Expand Down
4 changes: 2 additions & 2 deletions CRM/Admin/Form/ScheduleReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public function parseActionSchedule($values) {
'end_date',
];

if (!CRM_Utils_Array::value('absolute_date', $params)) {
if (empty($params['absolute_date'])) {
$params['absolute_date'] = 'null';
}
foreach ($moreKeys as $mkey) {
Expand Down Expand Up @@ -577,7 +577,7 @@ public function parseActionSchedule($values) {

$params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0);

if (CRM_Utils_Array::value('is_repeat', $values) == 0) {
if (empty($values['is_repeat'])) {
$params['repetition_frequency_unit'] = 'null';
$params['repetition_frequency_interval'] = 'null';
$params['end_frequency_unit'] = 'null';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Form/Setting/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function postProcess() {
}

// add a new db locale if the requested language is not yet supported by the db
if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) {
if (empty($values['makeSinglelingual']) && !empty($values['addLanguage'])) {
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
if (!substr_count($domain->locales, $values['addLanguage'])) {
Expand Down
4 changes: 2 additions & 2 deletions CRM/Badge/BAO/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ public function labelCreator(&$formattedRow, $cellspacing = 0) {
break;
}
$this->pdf->Image($formattedRow['participant_image'], $x + $imageAlign, $y + $startOffset, CRM_Utils_Array::value('width_participant_image', $formattedRow), CRM_Utils_Array::value('height_participant_image', $formattedRow));
if ($startOffset == NULL && CRM_Utils_Array::value('height_participant_image', $formattedRow)) {
$startOffset = CRM_Utils_Array::value('height_participant_image', $formattedRow);
if ($startOffset == NULL && !empty($formattedRow['height_participant_image'])) {
$startOffset = $formattedRow['height_participant_image'];
}
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Case/Form/Activity/ChangeCaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static function beginPostProcess(&$form, &$params) {
$params['id'] = $form->_id;
}

if (CRM_Utils_Array::value('is_reset_timeline', $params) == 0) {
if (empty($params['is_reset_timeline'])) {
unset($params['reset_date_time']);
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/DedupeRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function preProcess() {
// check if $contactType is valid
$contactTypes = civicrm_api3('Contact', 'getOptions', ['field' => "contact_type", 'context' => "validate"]);
$contactType = CRM_Utils_Request::retrieve('contact_type', 'String', $this, FALSE, 0);
if (CRM_Utils_Array::value($contactType, $contactTypes['values'])) {
if (!empty($contactTypes['values'][$contactType])) {
$this->_contactType = $contactType;
}
elseif (!empty($contactType)) {
Expand Down
4 changes: 1 addition & 3 deletions CRM/Contact/Form/Task/ProximityCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ public static function formRule($fields, $files, $form) {
if (empty($fields['prox_state_province_id']) || empty($fields['prox_country_id'])) {
$errors["prox_state_province_id"] = ts("Country AND State/Province are required to search by distance.");
}
if (!CRM_Utils_Array::value('prox_postal_code', $fields) and
!CRM_Utils_Array::value('prox_city', $fields)
) {
if (empty($fields['prox_postal_code']) && empty($fields['prox_city'])) {
$errors["prox_distance"] = ts("City OR Postal Code are required to search by distance.");
}
}
Expand Down
6 changes: 3 additions & 3 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -2962,7 +2962,7 @@ public function _gatherMessageValues($input, &$values, $ids = []) {
if (!empty($lineItems)) {
$firstLineItem = reset($lineItems);
$priceSet = [];
if (CRM_Utils_Array::value('price_set_id', $firstLineItem)) {
if (!empty($firstLineItem['price_set_id'])) {
$priceSet = civicrm_api3('PriceSet', 'getsingle', [
'id' => $firstLineItem['price_set_id'],
'return' => 'is_quick_config, id',
Expand Down Expand Up @@ -4013,7 +4013,7 @@ public static function getPaymentInfo($id, $component = 'contribution', $getTrxn
$baseTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId);
$baseTrxnId = $baseTrxnId['financialTrxnId'];
}
if (!CRM_Utils_Array::value('total_amount', $total) || $usingLineTotal) {
if (empty($total['total_amount']) || $usingLineTotal) {
$total = CRM_Price_BAO_LineItem::getLineTotal($contributionId);
}
else {
Expand Down Expand Up @@ -5046,7 +5046,7 @@ protected function addContributionPageValuesToValuesHeavyHandedly(&$values) {
public static function checkContributeSettings($name = NULL, $checkInvoicing = FALSE) {
$contributeSettings = Civi::settings()->get('contribution_invoice_settings');

if ($checkInvoicing && !CRM_Utils_Array::value('invoicing', $contributeSettings)) {
if ($checkInvoicing && empty($contributeSettings['invoicing'])) {
return NULL;
}

Expand Down
6 changes: 3 additions & 3 deletions CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,10 @@ public function buildQuickForm() {
$componentDetails = [];
if ($this->_id) {
$componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
if (CRM_Utils_Array::value('membership', $componentDetails)) {
if (!empty($componentDetails['membership'])) {
$component = 'membership';
}
elseif (CRM_Utils_Array::value('participant', $componentDetails)) {
elseif (!empty($componentDetails['participant'])) {
$component = 'participant';
}
}
Expand Down Expand Up @@ -1710,7 +1710,7 @@ protected function submit($submittedValues, $action, $pledgePaymentID) {
protected function invoicingPostProcessHook($submittedValues, $action, $lineItem) {

$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
if (!CRM_Utils_Array::value('invoicing', $invoiceSettings)) {
if (empty($invoiceSettings['invoicing'])) {
return;
}
$taxRate = [];
Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static function handlePledge(&$form, $params, $contributionParams, $pledg
$pledgeParams['frequency_day'] = 1;
}
$pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
if (CRM_Utils_Array::value('start_date', $params)) {
if (!empty($params['start_date'])) {
$pledgeParams['frequency_day'] = intval(date("d", strtotime(CRM_Utils_Array::value('start_date', $params))));
$pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date('Ymd', strtotime(CRM_Utils_Array::value('start_date', $params)));
}
Expand Down Expand Up @@ -1942,7 +1942,7 @@ public static function submit($params) {
$form->_fields['billing_first_name'] = 1;
$form->_fields['billing_last_name'] = 1;
// CRM-18854 - Set form values to allow pledge to be created for api test.
if (CRM_Utils_Array::value('pledge_block_id', $params)) {
if (!empty($params['pledge_block_id'])) {
$form->_values['pledge_id'] = CRM_Utils_Array::value('pledge_id', $params, NULL);
$form->_values['pledge_block_id'] = $params['pledge_block_id'];
$pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($params['id']);
Expand Down
10 changes: 5 additions & 5 deletions CRM/Contribute/Form/Contribution/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -915,13 +915,13 @@ public static function formRule($fields, $files, $self) {
$errors['pledge_installments'] = ts('Please enter a valid number of pledge installments.');
}
else {
if (CRM_Utils_Array::value('pledge_installments', $fields) == NULL) {
if (!isset($fields['pledge_installments'])) {
$errors['pledge_installments'] = ts('Pledge Installments is required field.');
}
elseif (CRM_Utils_Array::value('pledge_installments', $fields) == 1) {
$errors['pledge_installments'] = ts('Pledges consist of multiple scheduled payments. Select one-time contribution if you want to make your gift in a single payment.');
}
elseif (CRM_Utils_Array::value('pledge_installments', $fields) == 0) {
elseif (empty($fields['pledge_installments'])) {
$errors['pledge_installments'] = ts('Pledge Installments field must be > 1.');
}
}
Expand All @@ -931,10 +931,10 @@ public static function formRule($fields, $files, $self) {
$errors['pledge_frequency_interval'] = ts('Please enter a valid Pledge Frequency Interval.');
}
else {
if (CRM_Utils_Array::value('pledge_frequency_interval', $fields) == NULL) {
if (!isset($fields['pledge_frequency_interval'])) {
$errors['pledge_frequency_interval'] = ts('Pledge Frequency Interval. is required field.');
}
elseif (CRM_Utils_Array::value('pledge_frequency_interval', $fields) == 0) {
elseif (empty($fields['pledge_frequency_interval'])) {
$errors['pledge_frequency_interval'] = ts('Pledge frequency interval field must be > 0');
}
}
Expand All @@ -947,7 +947,7 @@ public static function formRule($fields, $files, $self) {
return $errors;
}

if (CRM_Utils_Array::value('payment_processor_id', $fields) === NULL) {
if (!isset($fields['payment_processor_id'])) {
$errors['payment_processor_id'] = ts('Payment Method is a required field.');
}
else {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function setDefaultValues() {
];
foreach ($pledgeBlock as $key) {
$defaults[$key] = CRM_Utils_Array::value($key, $pledgeBlockDefaults);
if ($key == 'pledge_start_date' && CRM_Utils_Array::value($key, $pledgeBlockDefaults)) {
if ($key == 'pledge_start_date' && !empty($pledgeBlockDefaults[$key])) {
$defaultPledgeDate = (array) json_decode($pledgeBlockDefaults['pledge_start_date']);
$pledgeDateFields = [
'pledge_calendar_date' => 'calendar_date',
Expand Down
10 changes: 5 additions & 5 deletions CRM/Contribute/Form/ContributionPage/Amount.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function buildQuickForm() {
if ($id != 0) {
$paymentProcessor[$id] = $processor['name'];
}
if (CRM_Utils_Array::value('is_recur', $processor)) {
if (!empty($processor['is_recur'])) {
$recurringPaymentProcessor[] = $id;
}
if (CRM_Utils_Array::value('object', $processor) && $processor['object']->supports('FutureRecurStartDate')) {
Expand Down Expand Up @@ -345,7 +345,7 @@ public static function formRule($fields, $files, $self) {
}

// CRM-18854 Check if recurring start date is in the future.
if (CRM_Utils_Array::value('pledge_calendar_date', $fields)) {
if (!empty($fields['pledge_calendar_date'])) {
if (date('Ymd') > date('Ymd', strtotime($fields['pledge_calendar_date']))) {
$errors['pledge_calendar_date'] = ts('The recurring start date cannot be prior to the current date.');
}
Expand Down Expand Up @@ -506,7 +506,7 @@ public function postProcess() {
$params['is_recur_installments'] = CRM_Utils_Array::value('is_recur_installments', $params, FALSE);
}

if (CRM_Utils_Array::value('adjust_recur_start_date', $params)) {
if (!empty($params['adjust_recur_start_date'])) {
$fieldValue = '';
$pledgeDateFields = [
'calendar_date' => 'pledge_calendar_date',
Expand All @@ -531,10 +531,10 @@ public function postProcess() {
$params['is_pledge_start_date_visible'] = 0;
$params['is_pledge_start_date_editable'] = 0;
}
if (!CRM_Utils_Array::value('is_pledge_start_date_visible', $params)) {
if (empty($params['is_pledge_start_date_visible'])) {
$params['is_pledge_start_date_visible'] = 0;
}
if (!CRM_Utils_Array::value('is_pledge_start_date_editable', $params)) {
if (empty($params['is_pledge_start_date_editable'])) {
$params['is_pledge_start_date_editable'] = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function create(&$params, $fixAddress = TRUE, $entity = NULL) {
// when we come from a form which displays all the location elements (like the edit form or the inline block
// elements, we can skip the below check. The below check adds quite a feq queries to an already overloaded
// form
if (!CRM_Utils_Array::value('updateBlankLocInfo', $params, FALSE)) {
if (empty($params['updateBlankLocInfo'])) {
// make sure contact should have only one primary block, CRM-5051
self::checkPrimaryBlocks(CRM_Utils_Array::value('contact_id', $params));
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/RecurringEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ public function mapFormValuesToDB($formParams = []) {
}
}
if ($formParams['repeats_by'] == 2) {
if (CRM_Utils_Array::value('entity_status_1', $formParams) && CRM_Utils_Array::value('entity_status_2', $formParams)) {
if (CRM_Utils_Array::value('entity_status_1', $formParams) && !empty($formParams['entity_status_2'])) {
$dbParams['entity_status'] = $formParams['entity_status_1'] . " " . $formParams['entity_status_2'];
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public static function isEnvironmentSet($setting, $value = NULL) {
public static function isAPIJobAllowedToRun($params) {
$environment = CRM_Core_Config::environment(NULL, TRUE);
if ($environment != 'Production') {
if (CRM_Utils_Array::value('runInNonProductionEnvironment', $params)) {
if (!empty($params['runInNonProductionEnvironment'])) {
$mailing = Civi::settings()->get('mailing_backend_store');
if ($mailing) {
Civi::settings()->set('mailing_backend', $mailing);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/StatusPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function create($params) {
}

// Check if this StatusPreference already exists.
if (empty($params['id']) && CRM_Utils_Array::value('name', $params)) {
if (empty($params['id']) && !empty($params['name'])) {
$statusPreference->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
$statusPreference->name = $params['name'];

Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/UFField.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ public static function assignAddressField($key, &$profileAddressFields, $profile
if (in_array($field['field_name'], $validBillingFields)) {
$validProfileFields[] = $field['field_name'];
}
if (CRM_Utils_Array::value('is_required', $field)) {
if (!empty($field['is_required'])) {
$requiredProfileFields[] = $field['field_name'];
}
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/DAO/AllCoreTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public static function getExports($dao, $labelName, $prefix, $foreignDAOs) {
$fields = $dao::fields();

foreach ($fields as $name => $field) {
if (CRM_Utils_Array::value('export', $field)) {
if (!empty($field['export'])) {
if ($prefix) {
$exports[$labelName] = & $fields[$name];
}
Expand Down Expand Up @@ -340,7 +340,7 @@ public static function getImports($dao, $labelName, $prefix, $foreignDAOs) {
$fields = $dao::fields();

foreach ($fields as $name => $field) {
if (CRM_Utils_Array::value('import', $field)) {
if (!empty($field['import'])) {
if ($prefix) {
$imports[$labelName] = & $fields[$name];
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public function addRowSelectors($rows) {
$this->addElement('checkbox', 'toggleSelect', NULL, NULL, ['class' => 'select-rows']);
if (!empty($rows)) {
foreach ($rows as $row) {
if (CRM_Utils_Array::value('checkbox', $row)) {
if (!empty($row['checkbox'])) {
$this->addElement('checkbox', $row['checkbox'], NULL, NULL, ['class' => 'select-row']);
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static function validateParams($requiredParams = [], $optionalParams = []
}

foreach ($optionalParams as $param => $type) {
if (CRM_Utils_Array::value($param, $_GET)) {
if (!empty($_GET[$param])) {
if (!is_array($_GET[$param])) {
$params[$param] = CRM_Utils_Type::validate(CRM_Utils_Array::value($param, $_GET), $type);
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Page/AJAX/RecurringEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CRM_Core_Page_AJAX_RecurringEntity {

public static function updateMode() {
$finalResult = [];
if (CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST)) {
if (CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && !empty($_REQUEST['entityTable'])) {
$mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer');
$entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer');
$entityTable = CRM_Utils_Type::escape($_REQUEST['entityTable'], 'String');
Expand Down
2 changes: 1 addition & 1 deletion CRM/Custom/Form/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function preProcess() {
if (!empty($defaults['is_view'])) {
CRM_Core_Error::statusBounce(ts('This field is view only so it will not display on edit form.'));
}
elseif (CRM_Utils_Array::value('is_active', $defaults) == 0) {
elseif (empty($defaults['is_active'])) {
CRM_Core_Error::statusBounce(ts('This field is inactive so it will not display on edit form.'));
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Cart/Form/Checkout/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function registerParticipant($params, &$participant, $event) {
if ($participant->must_wait) {
$participant_status = 'On waitlist';
}
elseif (CRM_Utils_Array::value('is_pay_later', $params, FALSE)) {
elseif (!empty($params['is_pay_later'])) {
$participant_status = 'Pending from pay later';
}
else {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/ManageEvent/Repeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static function checkRegistrationForEvents($eventID) {
$participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getRelatedEntities);
//Check if participants exists for events
foreach ($getRelatedEntities as $key => $value) {
if (!CRM_Utils_Array::value($value['id'], $participantDetails['countByID']) && $value['id'] != $eventID) {
if (empty($participantDetails['countByID'][$value['id']]) && $value['id'] != $eventID) {
//CRM_Event_BAO_Event::del($value['id']);
$eventIdsWithNoRegistration[] = $value['id'];
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public function assignToTemplate() {
$this->assign($v, $params[$v]);
}
}
elseif (CRM_Utils_Array::value('amount', $params) == 0) {
elseif (empty($params['amount'])) {
$this->assign($v, CRM_Utils_Array::value($v, $params));
}
}
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 @@ -457,7 +457,7 @@ public function postProcess() {
$participantCount[$participantNum] = 'participant';
}
$totalTaxAmount += CRM_Utils_Array::value('tax_amount', $record, 0);
if (CRM_Utils_Array::value('is_primary', $record)) {
if (!empty($record['is_primary'])) {
$taxAmount = &$params[$participantNum]['tax_amount'];
}
//lets get additional participant id to cancel.
Expand Down
Loading

0 comments on commit eb17a31

Please sign in to comment.