Skip to content

Commit b0bc4f4

Browse files
committed
Use null safe object operator where possible
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 82693da commit b0bc4f4

File tree

7 files changed

+25
-50
lines changed

7 files changed

+25
-50
lines changed

libraries/classes/Common.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,8 @@ private static function setDatabaseAndTableFromRequest(ContainerInterface $conta
540540
$db = DatabaseName::tryFromValue($request->getParam('db'));
541541
$table = TableName::tryFromValue($request->getParam('table'));
542542

543-
$GLOBALS['db'] = $db !== null ? $db->getName() : '';
544-
$GLOBALS['table'] = $table !== null ? $table->getName() : '';
543+
$GLOBALS['db'] = $db?->getName() ?? '';
544+
$GLOBALS['table'] = $table?->getName() ?? '';
545545

546546
if (! is_array($GLOBALS['urlParams'])) {
547547
$GLOBALS['urlParams'] = [];

libraries/classes/ConfigStorage/RelationParameters.php

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -371,48 +371,26 @@ public function toArray(): array
371371
return [
372372
'version' => Version::VERSION,
373373
'user' => $this->user,
374-
'db' => $this->db !== null ? $this->db->getName() : null,
375-
'bookmark' => $this->bookmarkFeature !== null ? $this->bookmarkFeature->bookmark->getName() : null,
376-
'central_columns' => $this->centralColumnsFeature !== null
377-
? $this->centralColumnsFeature->centralColumns->getName()
378-
: null,
374+
'db' => $this->db?->getName(),
375+
'bookmark' => $this->bookmarkFeature?->bookmark->getName(),
376+
'central_columns' => $this->centralColumnsFeature?->centralColumns->getName(),
379377
'column_info' => $columnInfo,
380-
'designer_settings' => $this->databaseDesignerSettingsFeature !== null
381-
? $this->databaseDesignerSettingsFeature->designerSettings->getName()
382-
: null,
383-
'export_templates' => $this->exportTemplatesFeature !== null
384-
? $this->exportTemplatesFeature->exportTemplates->getName()
385-
: null,
386-
'favorite' => $this->favoriteTablesFeature !== null
387-
? $this->favoriteTablesFeature->favorite->getName()
388-
: null,
389-
'history' => $this->sqlHistoryFeature !== null ? $this->sqlHistoryFeature->history->getName() : null,
390-
'navigationhiding' => $this->navigationItemsHidingFeature !== null
391-
? $this->navigationItemsHidingFeature->navigationHiding->getName()
392-
: null,
393-
'pdf_pages' => $this->pdfFeature !== null ? $this->pdfFeature->pdfPages->getName() : null,
394-
'recent' => $this->recentlyUsedTablesFeature !== null
395-
? $this->recentlyUsedTablesFeature->recent->getName()
396-
: null,
378+
'designer_settings' => $this->databaseDesignerSettingsFeature?->designerSettings->getName(),
379+
'export_templates' => $this->exportTemplatesFeature?->exportTemplates->getName(),
380+
'favorite' => $this->favoriteTablesFeature?->favorite->getName(),
381+
'history' => $this->sqlHistoryFeature?->history->getName(),
382+
'navigationhiding' => $this->navigationItemsHidingFeature?->navigationHiding->getName(),
383+
'pdf_pages' => $this->pdfFeature?->pdfPages->getName(),
384+
'recent' => $this->recentlyUsedTablesFeature?->recent->getName(),
397385
'relation' => $relation,
398-
'savedsearches' => $this->savedQueryByExampleSearchesFeature !== null
399-
? $this->savedQueryByExampleSearchesFeature->savedSearches->getName()
400-
: null,
401-
'table_coords' => $this->pdfFeature !== null ? $this->pdfFeature->tableCoords->getName() : null,
402-
'table_info' => $this->displayFeature !== null ? $this->displayFeature->tableInfo->getName() : null,
403-
'table_uiprefs' => $this->uiPreferencesFeature !== null
404-
? $this->uiPreferencesFeature->tableUiPrefs->getName()
405-
: null,
406-
'tracking' => $this->trackingFeature !== null ? $this->trackingFeature->tracking->getName() : null,
407-
'userconfig' => $this->userPreferencesFeature !== null
408-
? $this->userPreferencesFeature->userConfig->getName()
409-
: null,
410-
'usergroups' => $this->configurableMenusFeature !== null
411-
? $this->configurableMenusFeature->userGroups->getName()
412-
: null,
413-
'users' => $this->configurableMenusFeature !== null
414-
? $this->configurableMenusFeature->users->getName()
415-
: null,
386+
'savedsearches' => $this->savedQueryByExampleSearchesFeature?->savedSearches->getName(),
387+
'table_coords' => $this->pdfFeature?->tableCoords->getName(),
388+
'table_info' => $this->displayFeature?->tableInfo->getName(),
389+
'table_uiprefs' => $this->uiPreferencesFeature?->tableUiPrefs->getName(),
390+
'tracking' => $this->trackingFeature?->tracking->getName(),
391+
'userconfig' => $this->userPreferencesFeature?->userConfig->getName(),
392+
'usergroups' => $this->configurableMenusFeature?->userGroups->getName(),
393+
'users' => $this->configurableMenusFeature?->users->getName(),
416394
'bookmarkwork' => $this->bookmarkFeature !== null,
417395
'mimework' => $this->browserTransformationFeature !== null,
418396
'centralcolumnswork' => $this->centralColumnsFeature !== null,

libraries/classes/Controllers/CheckRelationsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __invoke(ServerRequest $request): void
5151
$relationParameters = $this->relation->getRelationParameters();
5252

5353
$this->render('relation/check_relations', [
54-
'db' => $db !== null ? $db->getName() : '',
54+
'db' => $db?->getName() ?? '',
5555
'zero_conf' => $GLOBALS['cfg']['ZeroConf'],
5656
'relation_parameters' => $relationParameters->toArray(),
5757
'sql_dir' => SQL_DIR,

libraries/classes/Controllers/Database/OperationsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function __invoke(ServerRequest $request): void
219219
if ($this->response->isAjax()) {
220220
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
221221
$this->response->addJSON('message', $GLOBALS['message']);
222-
$this->response->addJSON('newname', $newDatabaseName !== null ? $newDatabaseName->getName() : '');
222+
$this->response->addJSON('newname', $newDatabaseName?->getName() ?? '');
223223
$this->response->addJSON(
224224
'sql_query',
225225
Generator::getMessage('', $GLOBALS['sql_query'])

libraries/classes/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct()
5555

5656
/** @var Config|null $config */
5757
$config = $GLOBALS['config'];
58-
$cacheDir = $config !== null ? $config->getTempDir('twig') : null;
58+
$cacheDir = $config?->getTempDir('twig');
5959

6060
static::$twig = self::getTwigEnvironment($cacheDir);
6161
}

libraries/classes/Tracker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,13 +705,13 @@ public static function parseQuery($query): array
705705

706706
if ($options[6] === 'VIEW' || $options[6] === 'TABLE') {
707707
$result['identifier'] = 'CREATE ' . $options[6];
708-
$result['tablename'] = $statement->name !== null ? $statement->name->table : null;
708+
$result['tablename'] = $statement->name?->table;
709709
} elseif ($options[6] === 'DATABASE') {
710710
$result['identifier'] = 'CREATE DATABASE';
711711
$result['tablename'] = '';
712712

713713
// In case of CREATE DATABASE, database field of the CreateStatement is the name of the database
714-
$GLOBALS['db'] = $statement->name !== null ? $statement->name->database : null;
714+
$GLOBALS['db'] = $statement->name?->database;
715715
} elseif (
716716
$options[6] === 'INDEX'
717717
|| $options[6] === 'UNIQUE INDEX'

phpcs.xml.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment">
4949
<severity>4</severity>
5050
</rule>
51-
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator.RequiredNullSafeObjectOperator">
52-
<severity>4</severity>
53-
</rule>
5451
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall.MissingTrailingComma">
5552
<severity>4</severity>
5653
</rule>

0 commit comments

Comments
 (0)