Skip to content

Commit

Permalink
Fix ambiguous conditions replacing empty()
Browse files Browse the repository at this point in the history
  • Loading branch information
jensschuppe committed May 10, 2024
1 parent 48c49c1 commit 2b8ab81
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CRM/Twingle/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function matches($project_id) {
*/
public function getCustomFieldMapping() {
$custom_field_mapping = [];
if (is_string($custom_field_definition = $this->getAttribute('custom_field_mapping'))) {
if ('' !== ($custom_field_definition = $this->getAttribute('custom_field_mapping', ''))) {
/** @var string $custom_field_definition */
$custom_field_maps = preg_split(
'/\r\n|\r|\n/',
$custom_field_definition,
Expand Down
6 changes: 3 additions & 3 deletions CRM/Twingle/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static function validateSubmission(&$params, $profile = NULL): void {

// Get the payment instrument defined within the profile, or return an error
// if none matches (i.e. an unknown payment method was submitted).
$payment_instrument_id = $profile->getAttribute('pi_' . $params['payment_method']);
if (!isset($payment_instrument_id)) {
$payment_instrument_id = $profile->getAttribute('pi_' . $params['payment_method'], '');
if ('' !== $payment_instrument_id) {
throw new CRM_Core_Exception(
E::ts('Payment method could not be matched to existing payment instrument.'),
'invalid_format'
Expand Down Expand Up @@ -101,7 +101,7 @@ public static function validateSubmission(&$params, $profile = NULL): void {
// matches (i.e. an unknown gender was submitted).
if (is_string($params['user_gender'])) {
$gender_id = $profile->getAttribute('gender_' . $params['user_gender']);
if (!isset($gender_id)) {
if (!is_numeric($gender_id)) {
throw new CRM_Core_Exception(
E::ts('Gender could not be matched to existing gender.'),
'invalid_format'
Expand Down
6 changes: 3 additions & 3 deletions api/v3/TwingleDonation/Submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ function civicrm_api3_twingle_donation_Submit($params) {
// Get the prefix ID defined within the profile
if (
isset($params['user_gender'])
&& NULL !== ($prefix_id = $profile->getAttribute('prefix_' . $params['user_gender']))
&& is_numeric($prefix_id = $profile->getAttribute('prefix_' . $params['user_gender']))
) {
$contact_data['prefix_id'] = $prefix_id;
}
Expand Down Expand Up @@ -830,8 +830,8 @@ function civicrm_api3_twingle_donation_Submit($params) {
$result_values['membership'] = $membership;

// call the postprocess API
$postprocess_call = $profile->getAttribute('membership_postprocess_call');
if (is_string($postprocess_call)) {
if ('' !== ($postprocess_call = $profile->getAttribute('membership_postprocess_call', ''))) {
/** @var string $postprocess_call */
[$pp_entity, $pp_action] = explode('.', $postprocess_call, 2);
try {
// gather the contribution IDs
Expand Down

0 comments on commit 2b8ab81

Please sign in to comment.