From 9b69f5d0e32e1480034e36dbc5199e3ace7cb7a7 Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 24 Aug 2023 13:46:54 -0400 Subject: [PATCH] REF/Civi+api - Simplify inline conditionals with Elvis --- Civi/Angular/Manager.php | 2 +- Civi/Core/Themes.php | 2 +- Civi/Test/DbTestTrait.php | 4 ++-- api/v3/Activity.php | 2 +- api/v3/CustomValue.php | 4 ++-- setup/src/Setup.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Civi/Angular/Manager.php b/Civi/Angular/Manager.php index 3fb77b0f5d..9daf7ca622 100644 --- a/Civi/Angular/Manager.php +++ b/Civi/Angular/Manager.php @@ -56,7 +56,7 @@ class Manager { */ public function __construct($res, \CRM_Utils_Cache_Interface $cache = NULL) { $this->res = $res; - $this->cache = $cache ? $cache : new \CRM_Utils_Cache_ArrayCache([]); + $this->cache = $cache ?: new \CRM_Utils_Cache_ArrayCache([]); } /** diff --git a/Civi/Core/Themes.php b/Civi/Core/Themes.php index ebf6982227..05469ba937 100644 --- a/Civi/Core/Themes.php +++ b/Civi/Core/Themes.php @@ -57,7 +57,7 @@ class Themes extends \Civi\Core\Service\AutoService { * @param \CRM_Utils_Cache_Interface $cache */ public function __construct($cache = NULL) { - $this->cache = $cache ? $cache : Civi::cache('long'); + $this->cache = $cache ?: Civi::cache('long'); } /** diff --git a/Civi/Test/DbTestTrait.php b/Civi/Test/DbTestTrait.php index ff81b0e0d5..bdfcbfe9a8 100644 --- a/Civi/Test/DbTestTrait.php +++ b/Civi/Test/DbTestTrait.php @@ -111,7 +111,7 @@ trait DbTestTrait { * @param null $message */ public function assertDBRowNotExist($daoName, $id, $message = NULL) { - $message = $message ? $message : "$daoName (#$id) should not exist"; + $message = $message ?: "$daoName (#$id) should not exist"; $value = \CRM_Core_DAO::getFieldValue($daoName, $id, 'id', 'id', TRUE); $this->assertNull($value, $message); } @@ -123,7 +123,7 @@ trait DbTestTrait { * @param null $message */ public function assertDBRowExist($daoName, $id, $message = NULL) { - $message = $message ? $message : "$daoName (#$id) should exist"; + $message = $message ?: "$daoName (#$id) should exist"; $value = \CRM_Core_DAO::getFieldValue($daoName, $id, 'id', 'id', TRUE); $this->assertEquals($id, $value, $message); } diff --git a/api/v3/Activity.php b/api/v3/Activity.php index 6d95e7ca2a..89ce4e5842 100644 --- a/api/v3/Activity.php +++ b/api/v3/Activity.php @@ -641,7 +641,7 @@ function _civicrm_api3_activity_check_params(&$params) { $activityTypeId = $params['activity_type_id'] ?? NULL; if ($activityName || $activityLabel) { - $activityTypeIdInList = array_search(($activityName ? $activityName : $activityLabel), $activityTypes); + $activityTypeIdInList = array_search(($activityName ?: $activityLabel), $activityTypes); if (!$activityTypeIdInList) { $errorString = $activityName ? "Invalid Activity Name : $activityName" : "Invalid Activity Type Label"; diff --git a/api/v3/CustomValue.php b/api/v3/CustomValue.php index f3b127c177..252adeb0f6 100644 --- a/api/v3/CustomValue.php +++ b/api/v3/CustomValue.php @@ -345,14 +345,14 @@ function civicrm_api3_custom_value_gettree($params) { $result = []; foreach ($tree as $group) { $result[$group['name']] = []; - $groupToReturn = $toReturn['custom_group'] ? $toReturn['custom_group'] : array_keys($group); + $groupToReturn = $toReturn['custom_group'] ?: array_keys($group); foreach ($groupToReturn as $item) { $result[$group['name']][$item] = $group[$item] ?? NULL; } $result[$group['name']]['fields'] = []; foreach ($group['fields'] as $fieldInfo) { $field = ['value' => NULL]; - $fieldToReturn = $toReturn['custom_field'] ? $toReturn['custom_field'] : array_keys($fieldInfo); + $fieldToReturn = $toReturn['custom_field'] ?: array_keys($fieldInfo); foreach ($fieldToReturn as $item) { $field[$item] = $fieldInfo[$item] ?? NULL; } diff --git a/setup/src/Setup.php b/setup/src/Setup.php index 18e38b8964..1d7ead79db 100644 --- a/setup/src/Setup.php +++ b/setup/src/Setup.php @@ -77,7 +77,7 @@ class Setup { '/^civi\.setupui\./' => 'run', '/./' => 'fail', ]); - self::$instance->log = $log ? $log : new NullLogger(); + self::$instance->log = $log ?: new NullLogger(); $pluginDir = dirname(__DIR__) . '/plugins'; $pluginFiles = array(); -- 2.25.1