From fe0dbedaa47da4d31b6add5170286473ec98f9e8 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 17 Mar 2020 19:34:12 -0400 Subject: [PATCH] CRM/Utils - Cleanup boolean expressions --- CRM/Utils/File.php | 2 +- CRM/Utils/Rule.php | 8 ++++---- CRM/Utils/System.php | 4 +--- CRM/Utils/System/Drupal6.php | 2 +- CRM/Utils/System/Drupal8.php | 2 +- CRM/Utils/System/DrupalBase.php | 2 +- CRM/Utils/System/Joomla.php | 2 +- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/CRM/Utils/File.php b/CRM/Utils/File.php index 85700778f427..11b8422a733d 100644 --- a/CRM/Utils/File.php +++ b/CRM/Utils/File.php @@ -399,7 +399,7 @@ public static function isExtensionSafe($ext) { } } // support lower and uppercase file extensions - return isset($extensions[strtolower($ext)]) ? TRUE : FALSE; + return (bool) isset($extensions[strtolower($ext)]); } /** diff --git a/CRM/Utils/Rule.php b/CRM/Utils/Rule.php index cbe4ed8f8291..65cfebc62519 100644 --- a/CRM/Utils/Rule.php +++ b/CRM/Utils/Rule.php @@ -492,7 +492,7 @@ public static function numeric($value) { return FALSE; } - return preg_match('/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/', $value) ? TRUE : FALSE; + return (bool) preg_match('/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/', $value); } /** @@ -513,7 +513,7 @@ public static function numeric($value) { * @return bool */ public static function alphanumeric($value) { - return preg_match('/^[a-zA-Z0-9_-]*$/', $value) ? TRUE : FALSE; + return (bool) preg_match('/^[a-zA-Z0-9_-]*$/', $value); } /** @@ -523,7 +523,7 @@ public static function alphanumeric($value) { * @return bool */ public static function numberOfDigit($value, $noOfDigit) { - return preg_match('/^\d{' . $noOfDigit . '}$/', $value) ? TRUE : FALSE; + return (bool) preg_match('/^\d{' . $noOfDigit . '}$/', $value); } /** @@ -605,7 +605,7 @@ public static function money($value) { // Allow values such as -0, 1.024555, -.1 // We need to support multiple decimal places here, not just the number allowed by locale // otherwise tax calculations break when you want the inclusive amount to be a round number (eg. £10 inc. VAT requires 8.333333333 here). - return preg_match('/(^-?\d+\.?\d*$)|(^-?\.\d+$)/', $value) ? TRUE : FALSE; + return (bool) preg_match('/(^-?\d+\.?\d*$)|(^-?\.\d+$)/', $value); } /** diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 43a6e22c06eb..a8f78576e328 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -1192,9 +1192,7 @@ public static function getRequestHeaders() { * this function, please go and change the code in the install script as well. */ public static function isSSL() { - return (isset($_SERVER['HTTPS']) && - !empty($_SERVER['HTTPS']) && - strtolower($_SERVER['HTTPS']) != 'off') ? TRUE : FALSE; + return !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off'; } /** diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index 26167f93dc3e..0ac291164ef0 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -687,7 +687,7 @@ public function getModules() { $result = []; $q = db_query('SELECT name, status FROM {system} WHERE type = \'module\' AND schema_version <> -1'); while ($row = db_fetch_object($q)) { - $result[] = new CRM_Core_Module('drupal.' . $row->name, ($row->status == 1) ? TRUE : FALSE); + $result[] = new CRM_Core_Module('drupal.' . $row->name, $row->status == 1); } return $result; } diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index 072e01227052..49d39ca6d778 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -541,7 +541,7 @@ public function getModules() { foreach ($module_data as $module_name => $extension) { if (!isset($extension->info['hidden']) && $extension->origin != 'core') { $extension->schema_version = drupal_get_installed_schema_version($module_name); - $modules[] = new CRM_Core_Module('drupal.' . $module_name, ($extension->status == 1 ? TRUE : FALSE)); + $modules[] = new CRM_Core_Module('drupal.' . $module_name, ($extension->status == 1)); } } return $modules; diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index 380a9f07d904..c54fb3db1177 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -294,7 +294,7 @@ public function getModules() { $result = []; $q = db_query('SELECT name, status FROM {system} WHERE type = \'module\' AND schema_version <> -1'); foreach ($q as $row) { - $result[] = new CRM_Core_Module('drupal.' . $row->name, ($row->status == 1) ? TRUE : FALSE); + $result[] = new CRM_Core_Module('drupal.' . $row->name, $row->status == 1); } return $result; } diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index 9d24ba0ef1a7..5a42e662b778 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -693,7 +693,7 @@ public function getModules() { foreach ($plugins as $plugin) { // question: is the folder really a critical part of the plugin's name? $name = implode('.', ['joomla', $plugin['type'], $plugin['folder'], $plugin['element']]); - $result[] = new CRM_Core_Module($name, $plugin['enabled'] ? TRUE : FALSE); + $result[] = new CRM_Core_Module($name, !empty($plugin['enabled'])); } return $result;