Skip to content

Commit

Permalink
Merge pull request #17091 from colemanw/noArrayValue
Browse files Browse the repository at this point in the history
[REF] Switch CRM_Utils_Array::value to empty in conditionals
  • Loading branch information
seamuslee001 authored May 4, 2020
2 parents 0fdffe8 + b99f3e9 commit 4038698
Show file tree
Hide file tree
Showing 31 changed files with 42 additions and 45 deletions.
2 changes: 1 addition & 1 deletion CRM/Activity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static function permissionedTaskTitles($permission, $params = []) {
*/
public static function getTask($value) {
self::tasks();
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
if (!$value || empty(self::$_tasks[$value])) {
// make the print task by default
$value = self::TASK_PRINT;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Form/Preferences/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function postProcess() {

// check that locale supports address parsing
if (
CRM_Utils_Array::value($addressOptions['Street Address Parsing'], $this->_params['address_options']) &&
!empty($this->_params['address_options'][$addressOptions['Street Address Parsing']]) &&
!CRM_Core_BAO_Address::isSupportedParsingLocale()
) {
$config = CRM_Core_Config::singleton();
Expand Down
2 changes: 1 addition & 1 deletion CRM/Campaign/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static function permissionedTaskTitles($permission, $params = []) {
*/
public static function getTask($value) {
self::tasks();
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
if (!$value || empty(self::$_tasks[$value])) {
// Set the interview task as default
$value = self::INTERVIEW;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Case/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static function permissionedTaskTitles($permission, $params = []) {
*/
public static function getTask($value) {
self::tasks();
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
if (!$value || empty(self::$_tasks[$value])) {
// make the print task by default
$value = self::TASK_PRINT;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,7 @@ public static function fromClause(&$tables, $inner = NULL, $right = NULL, $prima
}

if ((!empty($tables['civicrm_state_province']) || !empty($tables['civicrm_country']) ||
CRM_Utils_Array::value('civicrm_county', $tables)) && empty($tables['civicrm_address'])) {
!empty($tables['civicrm_county'])) && empty($tables['civicrm_address'])) {
$tables = array_merge(['civicrm_address' => 1],
$tables
);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Search/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function buildQuickForm() {

// see if we need to include this paneName in the current form
if ($this->_searchPane == $type || !empty($_POST["hidden_{$type}"]) ||
CRM_Utils_Array::value("hidden_{$type}", $this->_formValues)
!empty($this->_formValues["hidden_{$type}"])
) {
$allPanes[$name]['open'] = 'true';

Expand Down
8 changes: 2 additions & 6 deletions CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,7 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
);
}
elseif ((is_numeric(CRM_Utils_Array::value('geo_code_1', $row))) ||
(!empty($row['city']) &&
CRM_Utils_Array::value('state_province', $row)
)
(!empty($row['city']) && !empty($row['state_province']))
) {
$row['action'] = CRM_Core_Action::formLink(
$links,
Expand Down Expand Up @@ -935,9 +933,7 @@ public function addActions(&$rows) {
}

if ((!is_numeric(CRM_Utils_Array::value('geo_code_1', $row))) &&
(empty($row['city']) ||
!CRM_Utils_Array::value('state_province', $row)
)
(empty($row['city']) || empty($row['state_province']))
) {
$mask = $mask & 4095;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function add(&$params, $ids = []) {
$contributionStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', (int) $params['contribution_status_id']);

if (!$contributionID
&& CRM_Utils_Array::value('membership_id', $params)
&& !empty($params['membership_id'])
&& Civi::settings()->get('deferred_revenue_enabled')
) {
$memberStartDate = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $params['membership_id'], 'start_date');
Expand Down
10 changes: 5 additions & 5 deletions CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function setDefaultValues() {
$defaults['total_amount'] = CRM_Utils_Money::format($total_value, NULL, '%a');
if (!empty($defaults['tax_amount'])) {
$componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
if (!(CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails))) {
if (empty($componentDetails['membership']) && empty($componentDetails['participant'])) {
$defaults['total_amount'] = CRM_Utils_Money::format($total_value - $defaults['tax_amount'], NULL, '%a');
}
}
Expand Down Expand Up @@ -483,7 +483,7 @@ public function buildQuickForm() {
// FIXME: This probably needs to be done in preprocess
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
&& $this->_action & CRM_Core_Action::UPDATE
&& CRM_Utils_Array::value('financial_type_id', $this->_values)
&& !empty($this->_values['financial_type_id'])
) {
$financialTypeID = CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']);
CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($this->_id, 'edit');
Expand Down Expand Up @@ -1253,7 +1253,7 @@ protected function generatePane($type, $defaults) {

// See if we need to include this paneName in the current form.
if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) ||
CRM_Utils_Array::value("hidden_{$type}", $defaults)
!empty($defaults["hidden_{$type}"])
) {
$this->assign('showAdditionalInfo', TRUE);
$pane['open'] = 'true';
Expand Down Expand Up @@ -1462,7 +1462,7 @@ protected function submit($submittedValues, $action, $pledgePaymentID) {
if ($this->_priceSetId && CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
//CRM-16833: Ensure tax is applied only once for membership conribution, when status changed.(e.g Pending to Completed).
$componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
if (!(CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails))) {
if (empty($componentDetails['membership']) && empty($componentDetails['participant'])) {
if (!($this->_action & CRM_Core_Action::UPDATE && (($this->_defaults['contribution_status_id'] != $submittedValues['contribution_status_id'])))) {
$lineItems[$itemId]['unit_price'] = $lineItems[$itemId]['line_total'] = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('total_amount', $submittedValues));
}
Expand Down Expand Up @@ -1499,7 +1499,7 @@ protected function submit($submittedValues, $action, $pledgePaymentID) {
// NOTE that this IS still a legitimate use of 'quick-config' for contributions under the current DB but
// we should look at having a price field per contribution type & then there would be little reason
// for the back-office contribution form postProcess to know if it is a quick-config form.
if ($isQuickConfig && !empty($submittedValues['financial_type_id']) && CRM_Utils_Array::value($this->_priceSetId, $lineItem)
if ($isQuickConfig && !empty($submittedValues['financial_type_id']) && !empty($lineItem[$this->_priceSetId])
) {
foreach ($lineItem[$this->_priceSetId] as &$values) {
$values['financial_type_id'] = $submittedValues['financial_type_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 @@ -1871,7 +1871,7 @@ public function setFormAmountFields($priceSetID) {
// the quick config seems like a red-herring - if this is about a separate membership payment then there
// are 2 types of line items - membership ones & non-membership ones - regardless of whether quick config is set
elseif (
CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock)
!empty($this->_membershipBlock['is_separate_payment'])
&& !empty($this->_values['fee'][$priceField->id])
&& ($this->_values['fee'][$priceField->id]['name'] == "other_amount")
&& CRM_Utils_Array::value("price_{$paramWeDoNotUnderstand}", $this->_params) < 1
Expand Down Expand Up @@ -2052,8 +2052,8 @@ protected function processFormSubmission($contactID) {
// CRM-18854
if (!empty($this->_params['is_pledge']) && empty($this->_values['pledge_id']) && !empty($this->_values['adjust_recur_start_date'])) {
$pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id);
if (CRM_Utils_Array::value('start_date', $this->_params) || !CRM_Utils_Array::value('is_pledge_start_date_visible', $pledgeBlock)
|| !CRM_Utils_Array::value('is_pledge_start_date_editable', $pledgeBlock)) {
if (!empty($this->_params['start_date']) || empty($pledgeBlock['is_pledge_start_date_visible'])
|| empty($pledgeBlock['is_pledge_start_date_editable'])) {
$pledgeStartDate = $this->_params['start_date'] ?? NULL;
$this->_params['receive_date'] = CRM_Pledge_BAO_Pledge::getPledgeStartDate($pledgeStartDate, $pledgeBlock);
$recurParams = CRM_Pledge_BAO_Pledge::buildRecurParams($this->_params);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/Contribution/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ public static function formRule($fields, $files, $self) {
(int) $self->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON
) {
if (!empty($fields[$self->_expressButtonName . '_x']) || !empty($fields[$self->_expressButtonName . '_y']) ||
CRM_Utils_Array::value($self->_expressButtonName, $fields)
!empty($fields[$self->_expressButtonName])
) {
return $errors;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ protected function setRecurringMembershipParams() {
}
if ((!empty($this->_params['selectMembership']) || !empty($this->_params['priceSetId']))
&& !empty($this->_paymentProcessor['is_recur']) &&
CRM_Utils_Array::value('auto_renew', $this->_params)
!empty($this->_params['auto_renew'])
&& empty($this->_params['is_recur']) && empty($this->_params['frequency_interval'])
) {

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/SoftCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static function formRule($fields, $errors, $self) {
// if honor roll fields are populated but no PCP is selected
if (empty($fields['pcp_made_through_id'])) {
if (!empty($fields['pcp_display_in_roll']) || !empty($fields['pcp_roll_nickname']) ||
CRM_Utils_Array::value('pcp_personal_note', $fields)
!empty($fields['pcp_personal_note'])
) {
$errors['pcp_made_through_id'] = ts('Please select a Personal Campaign Page, OR uncheck Display in Honor Roll and clear both the Honor Roll Name and the Personal Note field.');
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/Task/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public static function getElements($contribIds, $params, $contactIds) {
foreach ($contactDetails as $id => $values) {
if (empty($values['email']) ||
(empty($params['override_privacy']) && !empty($values['do_not_email']))
|| CRM_Utils_Array::value('is_deceased', $values)
|| !empty($values['is_deceased'])
|| !empty($values['on_hold'])
) {
$suppressedEmails++;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static function permissionedTaskTitles($permission, $params = []) {
*/
public static function getTask($value) {
self::tasks();
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
if (!$value || empty(self::$_tasks[$value])) {
// make the print task by default
$value = self::TASK_PRINT;
}
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 @@ -685,7 +685,7 @@ public static function triggerInsert($event) {
if (empty($hasaRecurringRecord)) {
// check if its a linked entity
if (array_key_exists($obj->__table, self::$_linkedEntitiesInfo) &&
!CRM_Utils_Array::value('is_multirecord', self::$_linkedEntitiesInfo[$obj->__table])
empty(self::$_linkedEntitiesInfo[$obj->__table]['is_multirecord'])
) {
$linkedDAO = new self::$_tableDAOMapper[$obj->__table]();
$linkedDAO->id = $obj->id;
Expand Down
5 changes: 3 additions & 2 deletions CRM/Core/Invoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function _invoke($args) {
return NULL;
}
// CRM-15901: Turn off PHP errors display for all ajax calls
if (CRM_Utils_Array::value(1, $args) == 'ajax' || CRM_Utils_Array::value('snippet', $_REQUEST)) {
if (CRM_Utils_Array::value(1, $args) == 'ajax' || !empty($_REQUEST['snippet'])) {
ini_set('display_errors', 0);
}

Expand Down Expand Up @@ -184,7 +184,8 @@ private static function registerPharHandler() {
stream_wrapper_unregister('phar');
stream_wrapper_register('phar', \TYPO3\PharStreamWrapper\PharStreamWrapper::class);
}
} else {
}
else {
// this is not an exception we can handle
throw $e;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ public function buildEventFeeForm($form) {
);
}
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
&& !CRM_Utils_Array::value('fee', $form->_values)
&& empty($form->_values['fee'])
&& CRM_Utils_Array::value('snippet', $_REQUEST) == CRM_Core_Smarty::PRINT_NOFORM
) {
CRM_Core_Session::setStatus(ts('You do not have all the permissions needed for this page.'), 'Permission Denied', 'error');
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/Registration/AdditionalParticipant.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ public function postProcess() {
// CRM-11182 - Optional confirmation screen
!$this->_values['event']['is_confirm_enabled']
&& !$this->_values['event']['is_monetary']
&& CRM_Utils_Array::value('additional_participants', $this->_params[0])
&& !empty($this->_params[0]['additional_participants'])
&& $this->isLastParticipant()
) {
$this->processRegistration($this->_params);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/SelfSvcTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public static function checkProfileComplete($fields, &$errors, $self) {
}
}
if (!$email && !(CRM_Utils_Array::value('first_name', $fields) &&
CRM_Utils_Array::value('last_name', $fields))) {
!empty($fields['last_name']))) {
$defaults = $params = ['id' => $eventId];
CRM_Event_BAO_Event::retrieve($params, $defaults);
$message = ts("Mandatory fields (first name and last name, OR email address) are missing from this form.");
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static function permissionedTaskTitles($permission, $params = []) {
*/
public static function getTask($value) {
self::tasks();
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
if (!$value || empty(self::$_tasks[$value])) {
// make the print task by default
$value = self::TASK_PRINT;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function permissionedTaskTitles($permission, $params = []) {
*/
public static function getTask($value) {
self::tasks();
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
if (!$value || empty(self::$_tasks[$value])) {
// make the print task by default
$value = self::TASK_PRINT;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public static function buildSearchForm(&$form) {
* @param array $tables
*/
public static function tableNames(&$tables) {
if (!empty($tables['civicrm_membership_log']) || !empty($tables['civicrm_membership_status']) || CRM_Utils_Array::value('civicrm_membership_type', $tables)) {
if (!empty($tables['civicrm_membership_log']) || !empty($tables['civicrm_membership_status']) || !empty($tables['civicrm_membership_type'])) {
$tables = array_merge(['civicrm_membership' => 1], $tables);
}
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Member/Page/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public function browse() {
}

// if relevant--membership is active and type allows inheritance--count related memberships
if (CRM_Utils_Array::value('is_current_member', $statusANDType[$dao->id])
&& CRM_Utils_Array::value('relationship_type_id', $statusANDType[$dao->id])
if (!empty($statusANDType[$dao->id]['is_current_member'])
&& !empty($statusANDType[$dao->id]['relationship_type_id'])
&& empty($dao->owner_membership_id)
) {
// not an related membership
Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static function permissionedTaskTitles($permission, $params = []) {
*/
public static function getTask($value) {
self::tasks();
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
if (!$value || empty(self::$_tasks[$value])) {
// Make the print task the default
$value = self::TASK_PRINT;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Pledge/Form/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function buildQuickForm() {
];
// see if we need to include this paneName in the current form
if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) ||
CRM_Utils_Array::value("hidden_{$type}", $defaults)
!empty($defaults["hidden_{$type}"])
) {
$showAdditionalInfo = TRUE;
$allPanes[$name]['open'] = 'true';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Profile/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ public function postProcess() {
$details = $contactDetails[$this->_id];
}
if (!(!empty($details['addressee_id']) || !empty($details['email_greeting_id']) ||
CRM_Utils_Array::value('postal_greeting_id', $details)
!empty($details['postal_greeting_id'])
)
) {

Expand Down
2 changes: 1 addition & 1 deletion CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5835,7 +5835,7 @@ protected function buildColumns($specs, $tableName, $daoName = NULL, $tableAlias
*/
protected function storeGroupByArray() {

if (!CRM_Utils_Array::value('group_bys', $this->_params)
if (empty($this->_params['group_bys'])
|| !is_array($this->_params['group_bys'])) {
$this->_params['group_bys'] = [];
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Report/Form/Campaign/SurveyDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function select() {
foreach ($table['fields'] as $fieldName => $field) {
if (!empty($field['required']) ||
!empty($this->_params['fields'][$fieldName]) ||
CRM_Utils_Array::value('is_required', $field)
!empty($field['is_required'])
) {

$fieldsName = CRM_Utils_Array::value(1, explode('_', $tableName));
Expand Down
4 changes: 2 additions & 2 deletions CRM/Report/Form/Case/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,14 @@ public function checkEnabledFields() {

if (!empty($this->_params['last_completed_date_time_relative']) ||
!empty($this->_params['last_completed_date_time_from']) ||
CRM_Utils_Array::value('last_completed_date_time_to', $this->_params)
!empty($this->_params['last_completed_date_time_to'])
) {
$this->_activityLastCompleted = TRUE;
}

if (!empty($this->_params['last_activity_date_time_relative']) ||
!empty($this->_params['last_activity_date_time_from']) ||
CRM_Utils_Array::value('last_activity_date_time_to', $this->_params)
!empty($this->_params['last_activity_date_time_to'])
) {
$this->_activityLast = TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ public static function getApiTokenReplacement($entity, $token, $entityArray) {
*/
public static function replaceContributionTokens($str, &$contribution, $html = FALSE, $knownTokens = NULL, $escapeSmarty = FALSE) {
$key = 'contribution';
if (!$knownTokens || !CRM_Utils_Array::value($key, $knownTokens)) {
if (!$knownTokens || empty($knownTokens[$key])) {
//early return
return $str;
}
Expand Down

0 comments on commit 4038698

Please sign in to comment.