From b0bc4f460ed73ae1ca1afa5cd88e074a98412109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 20 Feb 2023 18:21:56 -0300 Subject: [PATCH] Use null safe object operator where possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Common.php | 4 +- .../ConfigStorage/RelationParameters.php | 58 ++++++------------- .../Controllers/CheckRelationsController.php | 2 +- .../Database/OperationsController.php | 2 +- libraries/classes/Template.php | 2 +- libraries/classes/Tracker.php | 4 +- phpcs.xml.dist | 3 - 7 files changed, 25 insertions(+), 50 deletions(-) diff --git a/libraries/classes/Common.php b/libraries/classes/Common.php index f4826fc9f3..476221395e 100644 --- a/libraries/classes/Common.php +++ b/libraries/classes/Common.php @@ -540,8 +540,8 @@ final class Common $db = DatabaseName::tryFromValue($request->getParam('db')); $table = TableName::tryFromValue($request->getParam('table')); - $GLOBALS['db'] = $db !== null ? $db->getName() : ''; - $GLOBALS['table'] = $table !== null ? $table->getName() : ''; + $GLOBALS['db'] = $db?->getName() ?? ''; + $GLOBALS['table'] = $table?->getName() ?? ''; if (! is_array($GLOBALS['urlParams'])) { $GLOBALS['urlParams'] = []; diff --git a/libraries/classes/ConfigStorage/RelationParameters.php b/libraries/classes/ConfigStorage/RelationParameters.php index 1aff50c44b..307fbeafaf 100644 --- a/libraries/classes/ConfigStorage/RelationParameters.php +++ b/libraries/classes/ConfigStorage/RelationParameters.php @@ -371,48 +371,26 @@ final class RelationParameters return [ 'version' => Version::VERSION, 'user' => $this->user, - 'db' => $this->db !== null ? $this->db->getName() : null, - 'bookmark' => $this->bookmarkFeature !== null ? $this->bookmarkFeature->bookmark->getName() : null, - 'central_columns' => $this->centralColumnsFeature !== null - ? $this->centralColumnsFeature->centralColumns->getName() - : null, + 'db' => $this->db?->getName(), + 'bookmark' => $this->bookmarkFeature?->bookmark->getName(), + 'central_columns' => $this->centralColumnsFeature?->centralColumns->getName(), 'column_info' => $columnInfo, - 'designer_settings' => $this->databaseDesignerSettingsFeature !== null - ? $this->databaseDesignerSettingsFeature->designerSettings->getName() - : null, - 'export_templates' => $this->exportTemplatesFeature !== null - ? $this->exportTemplatesFeature->exportTemplates->getName() - : null, - 'favorite' => $this->favoriteTablesFeature !== null - ? $this->favoriteTablesFeature->favorite->getName() - : null, - 'history' => $this->sqlHistoryFeature !== null ? $this->sqlHistoryFeature->history->getName() : null, - 'navigationhiding' => $this->navigationItemsHidingFeature !== null - ? $this->navigationItemsHidingFeature->navigationHiding->getName() - : null, - 'pdf_pages' => $this->pdfFeature !== null ? $this->pdfFeature->pdfPages->getName() : null, - 'recent' => $this->recentlyUsedTablesFeature !== null - ? $this->recentlyUsedTablesFeature->recent->getName() - : null, + 'designer_settings' => $this->databaseDesignerSettingsFeature?->designerSettings->getName(), + 'export_templates' => $this->exportTemplatesFeature?->exportTemplates->getName(), + 'favorite' => $this->favoriteTablesFeature?->favorite->getName(), + 'history' => $this->sqlHistoryFeature?->history->getName(), + 'navigationhiding' => $this->navigationItemsHidingFeature?->navigationHiding->getName(), + 'pdf_pages' => $this->pdfFeature?->pdfPages->getName(), + 'recent' => $this->recentlyUsedTablesFeature?->recent->getName(), 'relation' => $relation, - 'savedsearches' => $this->savedQueryByExampleSearchesFeature !== null - ? $this->savedQueryByExampleSearchesFeature->savedSearches->getName() - : null, - 'table_coords' => $this->pdfFeature !== null ? $this->pdfFeature->tableCoords->getName() : null, - 'table_info' => $this->displayFeature !== null ? $this->displayFeature->tableInfo->getName() : null, - 'table_uiprefs' => $this->uiPreferencesFeature !== null - ? $this->uiPreferencesFeature->tableUiPrefs->getName() - : null, - 'tracking' => $this->trackingFeature !== null ? $this->trackingFeature->tracking->getName() : null, - 'userconfig' => $this->userPreferencesFeature !== null - ? $this->userPreferencesFeature->userConfig->getName() - : null, - 'usergroups' => $this->configurableMenusFeature !== null - ? $this->configurableMenusFeature->userGroups->getName() - : null, - 'users' => $this->configurableMenusFeature !== null - ? $this->configurableMenusFeature->users->getName() - : null, + 'savedsearches' => $this->savedQueryByExampleSearchesFeature?->savedSearches->getName(), + 'table_coords' => $this->pdfFeature?->tableCoords->getName(), + 'table_info' => $this->displayFeature?->tableInfo->getName(), + 'table_uiprefs' => $this->uiPreferencesFeature?->tableUiPrefs->getName(), + 'tracking' => $this->trackingFeature?->tracking->getName(), + 'userconfig' => $this->userPreferencesFeature?->userConfig->getName(), + 'usergroups' => $this->configurableMenusFeature?->userGroups->getName(), + 'users' => $this->configurableMenusFeature?->users->getName(), 'bookmarkwork' => $this->bookmarkFeature !== null, 'mimework' => $this->browserTransformationFeature !== null, 'centralcolumnswork' => $this->centralColumnsFeature !== null, diff --git a/libraries/classes/Controllers/CheckRelationsController.php b/libraries/classes/Controllers/CheckRelationsController.php index 48e22ba7f2..a188ddb741 100644 --- a/libraries/classes/Controllers/CheckRelationsController.php +++ b/libraries/classes/Controllers/CheckRelationsController.php @@ -51,7 +51,7 @@ class CheckRelationsController extends AbstractController $relationParameters = $this->relation->getRelationParameters(); $this->render('relation/check_relations', [ - 'db' => $db !== null ? $db->getName() : '', + 'db' => $db?->getName() ?? '', 'zero_conf' => $GLOBALS['cfg']['ZeroConf'], 'relation_parameters' => $relationParameters->toArray(), 'sql_dir' => SQL_DIR, diff --git a/libraries/classes/Controllers/Database/OperationsController.php b/libraries/classes/Controllers/Database/OperationsController.php index 125f2a6b45..5a59f736b7 100644 --- a/libraries/classes/Controllers/Database/OperationsController.php +++ b/libraries/classes/Controllers/Database/OperationsController.php @@ -219,7 +219,7 @@ class OperationsController extends AbstractController if ($this->response->isAjax()) { $this->response->setRequestStatus($GLOBALS['message']->isSuccess()); $this->response->addJSON('message', $GLOBALS['message']); - $this->response->addJSON('newname', $newDatabaseName !== null ? $newDatabaseName->getName() : ''); + $this->response->addJSON('newname', $newDatabaseName?->getName() ?? ''); $this->response->addJSON( 'sql_query', Generator::getMessage('', $GLOBALS['sql_query']) diff --git a/libraries/classes/Template.php b/libraries/classes/Template.php index 7a1449df9d..84d16d73cf 100644 --- a/libraries/classes/Template.php +++ b/libraries/classes/Template.php @@ -55,7 +55,7 @@ class Template /** @var Config|null $config */ $config = $GLOBALS['config']; - $cacheDir = $config !== null ? $config->getTempDir('twig') : null; + $cacheDir = $config?->getTempDir('twig'); static::$twig = self::getTwigEnvironment($cacheDir); } diff --git a/libraries/classes/Tracker.php b/libraries/classes/Tracker.php index ba1e6178ac..ec09d2dfde 100644 --- a/libraries/classes/Tracker.php +++ b/libraries/classes/Tracker.php @@ -705,13 +705,13 @@ class Tracker if ($options[6] === 'VIEW' || $options[6] === 'TABLE') { $result['identifier'] = 'CREATE ' . $options[6]; - $result['tablename'] = $statement->name !== null ? $statement->name->table : null; + $result['tablename'] = $statement->name?->table; } elseif ($options[6] === 'DATABASE') { $result['identifier'] = 'CREATE DATABASE'; $result['tablename'] = ''; // In case of CREATE DATABASE, database field of the CreateStatement is the name of the database - $GLOBALS['db'] = $statement->name !== null ? $statement->name->database : null; + $GLOBALS['db'] = $statement->name?->database; } elseif ( $options[6] === 'INDEX' || $options[6] === 'UNIQUE INDEX' diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 2e93181101..0f086776a5 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -48,9 +48,6 @@ 4 - - 4 - 4