From 91c561670c1883bcb64e2d07c77f5ab8c8da5938 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 30 Nov 2023 10:26:43 +1300 Subject: [PATCH] REF - Cleanup overly-verbose conditionals --- CRM/Contact/BAO/Individual.php | 6 +--- CRM/Core/BAO/CustomGroup.php | 6 +--- CRM/Core/CodeGen/Reflection.php | 6 +--- CRM/Core/CodeGen/Specification.php | 6 +--- CRM/Core/Permission.php | 6 +--- CRM/Mailing/BAO/MailingJob.php | 8 ++--- CRM/Utils/File.php | 6 +--- CRM/Utils/REST.php | 6 +--- CRM/Utils/Rule.php | 35 ++++--------------- bin/ContributionProcessor.php | 6 +--- ext/flexmailer/src/Listener/DefaultSender.php | 6 ++-- 11 files changed, 21 insertions(+), 76 deletions(-) diff --git a/CRM/Contact/BAO/Individual.php b/CRM/Contact/BAO/Individual.php index 200c7b54d7..7209ef5000 100644 --- a/CRM/Contact/BAO/Individual.php +++ b/CRM/Contact/BAO/Individual.php @@ -266,11 +266,7 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact { * @return bool */ public static function dataExists($params) { - if ($params['contact_type'] == 'Individual') { - return TRUE; - } - - return FALSE; + return $params['contact_type'] == 'Individual'; } } diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 69acff7378..3ae47793a5 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -2008,11 +2008,7 @@ SELECT civicrm_custom_group.id as groupID, civicrm_custom_group.title as groupT $query = "SELECT count(id) FROM {$tableName} WHERE id IS NOT NULL LIMIT 1"; $value = CRM_Core_DAO::singleValueQuery($query); - if (empty($value)) { - return TRUE; - } - - return FALSE; + return empty($value); } /** diff --git a/CRM/Core/CodeGen/Reflection.php b/CRM/Core/CodeGen/Reflection.php index 0dd7f23545..f6ba371f40 100644 --- a/CRM/Core/CodeGen/Reflection.php +++ b/CRM/Core/CodeGen/Reflection.php @@ -14,11 +14,7 @@ class CRM_Core_CodeGen_Reflection extends CRM_Core_CodeGen_BaseTask { // for the checksum. // skip this task on test environment as the schema generation should only be triggered during installation/upgrade - if (CIVICRM_UF == 'UnitTests') { - return FALSE; - } - - return TRUE; + return CIVICRM_UF !== 'UnitTests'; } /** diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index e64367f97b..24013d7257 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -552,11 +552,7 @@ class CRM_Core_CodeGen_Specification { */ private function getPhpNullable($fieldXML) { $required = $this->value('required', $fieldXML); - if ($required) { - return FALSE; - } - - return TRUE; + return !$required; } /** diff --git a/CRM/Core/Permission.php b/CRM/Core/Permission.php index f8f2fb7ace..2a852a6313 100644 --- a/CRM/Core/Permission.php +++ b/CRM/Core/Permission.php @@ -234,11 +234,7 @@ class CRM_Core_Permission { return TRUE; } - if (self::check('administer CiviCRM data', $userId)) { - return TRUE; - } - - return FALSE; + return self::check('administer CiviCRM data', $userId); } /** diff --git a/CRM/Mailing/BAO/MailingJob.php b/CRM/Mailing/BAO/MailingJob.php index 3d75980079..326da1cb8d 100644 --- a/CRM/Mailing/BAO/MailingJob.php +++ b/CRM/Mailing/BAO/MailingJob.php @@ -763,7 +763,7 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) // SMTP response code is buried in the message. $code = preg_match('/ \(code: (.+), response: /', $message, $matches) ? $matches[1] : ''; - if (strpos($message, 'Failed to write to socket') !== FALSE) { + if (str_contains($message, 'Failed to write to socket')) { return TRUE; } @@ -772,15 +772,15 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) return FALSE; } - if (strpos($message, 'Failed to set sender') !== FALSE) { + if (str_contains($message, 'Failed to set sender')) { return TRUE; } - if (strpos($message, 'Failed to add recipient') !== FALSE) { + if (str_contains($message, 'Failed to add recipient')) { return TRUE; } - if (strpos($message, 'Failed to send data') !== FALSE) { + if (str_contains($message, 'Failed to send data')) { return TRUE; } diff --git a/CRM/Utils/File.php b/CRM/Utils/File.php index 39a63c8fff..1c3ecdd54e 100644 --- a/CRM/Utils/File.php +++ b/CRM/Utils/File.php @@ -217,11 +217,7 @@ class CRM_Utils_File { $written = fwrite($file, $contents); $closed = fclose($file); - if ($written === FALSE or !$closed) { - return FALSE; - } - - return TRUE; + return !($written === FALSE or !$closed); } /** diff --git a/CRM/Utils/REST.php b/CRM/Utils/REST.php index f6a119c59d..6d245cc746 100644 --- a/CRM/Utils/REST.php +++ b/CRM/Utils/REST.php @@ -656,11 +656,7 @@ class CRM_Utils_REST { //
Browsers often retain list of credentials and re-send automatically. ]; - if (!empty($authx) && in_array($authx['flow'], $allowFlows)) { - return TRUE; - } - - return FALSE; + return (!empty($authx) && in_array($authx['flow'], $allowFlows)); } } diff --git a/CRM/Utils/Rule.php b/CRM/Utils/Rule.php index df620d1637..07ed44798c 100644 --- a/CRM/Utils/Rule.php +++ b/CRM/Utils/Rule.php @@ -36,11 +36,7 @@ class CRM_Utils_Rule { } // Make sure it include valid characters, alpha numeric and underscores - if (!preg_match('/^\w[\w\s\'\&\,\$\#\-\.\"\?\!]+$/i', $str)) { - return FALSE; - } - - return TRUE; + return (bool) preg_match('/^\w[\w\s\'\&\,\$\#\-\.\"\?\!]+$/i', $str); } /** @@ -64,11 +60,7 @@ class CRM_Utils_Rule { } // make sure it includes valid characters, alpha numeric and underscores - if (!preg_match('/^[\w]+$/i', $str)) { - return FALSE; - } - - return TRUE; + return (bool) preg_match('/^[\w]+$/i', $str); } /** @@ -92,11 +84,8 @@ class CRM_Utils_Rule { // * Composed of alphanumeric chars, underscore and hyphens. // * Maximum length of 64 chars. // * Optionally surrounded by backticks, in which case spaces also OK. - if (!preg_match('/^((`[-\w ]{1,64}`|[-\w]{1,64})\.)?(`[-\w ]{1,64}`|[-\w]{1,64})$/i', $str)) { - return FALSE; - } + return (bool) preg_match('/^((`[-\w ]{1,64}`|[-\w]{1,64})\.)?(`[-\w ]{1,64}`|[-\w]{1,64})$/i', $str); - return TRUE; } /** @@ -108,11 +97,7 @@ class CRM_Utils_Rule { * @return bool */ public static function mysqlOrderByDirection($str) { - if (!preg_match('/^(asc|desc)$/i', $str)) { - return FALSE; - } - - return TRUE; + return (bool) preg_match('/^(asc|desc)$/i', $str); } /** @@ -163,11 +148,7 @@ class CRM_Utils_Rule { // make sure it includes valid characters, alpha numeric and underscores // added (. and ,) option (CRM-1336) - if (!preg_match('/^[\w\s\.\,]+$/i', $str)) { - return FALSE; - } - - return TRUE; + return (bool) preg_match('/^[\w\s\.\,]+$/i', $str); } /** @@ -200,11 +181,7 @@ class CRM_Utils_Rule { } // make sure it includes valid characters, alpha numeric and underscores - if (!preg_match('/^[\w\s\%\'\&\,\$\#]+$/i', $query)) { - return FALSE; - } - - return TRUE; + return (bool) preg_match('/^[\w\s\%\'\&\,\$\#]+$/i', $query); } /** diff --git a/bin/ContributionProcessor.php b/bin/ContributionProcessor.php index 00b3776e0b..6dddb07a9b 100644 --- a/bin/ContributionProcessor.php +++ b/bin/ContributionProcessor.php @@ -450,11 +450,7 @@ class CiviContributeProcessor { } $contribution = CRM_Contribute_BAO_Contribution::create($params); - if (!$contribution->id) { - return FALSE; - } - - return TRUE; + return (bool) $contribution->id; } /** diff --git a/ext/flexmailer/src/Listener/DefaultSender.php b/ext/flexmailer/src/Listener/DefaultSender.php index d09386ff11..0d0a9e2f09 100644 --- a/ext/flexmailer/src/Listener/DefaultSender.php +++ b/ext/flexmailer/src/Listener/DefaultSender.php @@ -167,15 +167,15 @@ class DefaultSender extends BaseListener { return FALSE; } - if (strpos($message, 'Failed to set sender') !== FALSE) { + if (str_contains($message, 'Failed to set sender')) { return TRUE; } - if (strpos($message, 'Failed to add recipient') !== FALSE) { + if (str_contains($message, 'Failed to add recipient')) { return TRUE; } - if (strpos($message, 'Failed to send data') !== FALSE) { + if (str_contains($message, 'Failed to send data')) { return TRUE; } -- 2.25.1