Skip to content
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

CRM/Utils - Cleanup boolean expressions #16851

Merged
merged 1 commit into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Utils/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions CRM/Utils/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions CRM/Utils/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/System/Drupal6.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/System/Drupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/System/DrupalBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/System/Joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down