-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swap CRM_Utils_Array::value for empty() in conditionals #15005
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
) { | ||
$priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'); | ||
$params['priority_id'] = array_search('Normal', $priority); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
CRM_Core_Session::setStatus("", ts('Extension Upgraded'), "success"); | ||
} | ||
else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -523,7 +523,7 @@ public function parseActionSchedule($values) { | |
'end_date', | ||
]; | ||
|
||
if (!CRM_Utils_Array::value('absolute_date', $params)) { | ||
if (empty($params['absolute_date'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
$params['absolute_date'] = 'null'; | ||
} | ||
foreach ($moreKeys as $mkey) { | ||
|
@@ -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'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok - I guess is_repeat is a boolean - although that sort of thing always feels like a big assumption with our code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well since this statement uses loose |
||
$params['repetition_frequency_unit'] = 'null'; | ||
$params['repetition_frequency_interval'] = 'null'; | ||
$params['end_frequency_unit'] = 'null'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was silly as the conditional already established it was not empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean earlier in the formatLabel function? Anyway this seems ok but makes spidey-sense tingle for me for a different reason - out of scope here but for reference I don't see how $startOffset could be NULL, and even if it could be then adding it to $y in line 227 is iffy even if it works. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -631,9 +631,7 @@ public static function buildRecur(&$form) { | |
public static function formRule($fields, $files, $self) { | ||
$errors = []; | ||
$amount = self::computeAmount($fields, $self->_values); | ||
if (CRM_Utils_Array::value('auto_renew', $fields) && | ||
CRM_Utils_Array::value('payment_processor_id', $fields) == 0 | ||
) { | ||
if (!empty($fields['auto_renew']) && empty($fields['payment_processor_id'])) { | ||
$errors['auto_renew'] = ts('You cannot have auto-renewal on if you are paying later.'); | ||
} | ||
|
||
|
@@ -876,15 +874,13 @@ public static function formRule($fields, $files, $self) { | |
//CRM-16285 - Function to handle validation errors on form, for recurring contribution field. | ||
CRM_Contribute_BAO_ContributionRecur::validateRecurContribution($fields, $files, $self, $errors); | ||
|
||
if (!empty($fields['is_recur']) && | ||
CRM_Utils_Array::value('payment_processor_id', $fields) == 0 | ||
) { | ||
if (!empty($fields['is_recur']) && empty($fields['payment_processor_id'])) { | ||
$errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.'); | ||
} | ||
|
||
// validate PCP fields - if not anonymous, we need a nick name value | ||
if ($self->_pcpId && !empty($fields['pcp_display_in_roll']) && | ||
(CRM_Utils_Array::value('pcp_is_anonymous', $fields) == 0) && | ||
empty($fields['pcp_is_anonymous']) && | ||
CRM_Utils_Array::value('pcp_roll_nickname', $fields) == '' | ||
) { | ||
$errors['pcp_roll_nickname'] = ts('Please enter a name to include in the Honor Roll, or select \'contribute anonymously\'.'); | ||
|
@@ -915,13 +911,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.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ok. I r-run'd to check. Note that CRM_Utils_Rule::positiveInteger() above lets 0 thru (both int and string), and then as a string it gets thru here both originally and with the replacement, and then it gets caught down below by both the original and replacement on line 924. |
||
} | ||
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.'); | ||
} | ||
} | ||
|
@@ -931,10 +927,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'); | ||
} | ||
} | ||
|
@@ -947,7 +943,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 { | ||
|
@@ -1192,7 +1188,7 @@ public function submit($params) { | |
if ($params['amount'] != 0 && (($this->_values['is_pay_later'] && | ||
empty($this->_paymentProcessor) && | ||
!array_key_exists('hidden_processor', $params)) || | ||
(CRM_Utils_Array::value('payment_processor_id', $params) == 0)) | ||
empty($params['payment_processor_id'])) | ||
) { | ||
$params['is_pay_later'] = 1; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 (!empty($formParams['entity_status_1']) && !empty($formParams['entity_status_2'])) { | ||
$dbParams['entity_status'] = $formParams['entity_status_1'] . " " . $formParams['entity_status_2']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another instance where only the last one on the line was converted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. |
||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - it's not the same but I guess priority_id can't be 0....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this not the same @eileenmcnaughton? The default return value of
CRM_Utils_Array::value
is NULL if the variable isn't set, andisset($foo = NULL)
returns FALSE.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right - it could be set & equal to NULL or not set - I think here it doesn't matter in that set & equal to null would still be empty