Skip to content

Commit

Permalink
Use null safe object operator where possible
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Feb 20, 2023
1 parent 82693da commit b0bc4f4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 50 deletions.
4 changes: 2 additions & 2 deletions libraries/classes/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ private static function setDatabaseAndTableFromRequest(ContainerInterface $conta
$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'] = [];
Expand Down
58 changes: 18 additions & 40 deletions libraries/classes/ConfigStorage/RelationParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,48 +371,26 @@ public function toArray(): array
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,
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Controllers/CheckRelationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __invoke(ServerRequest $request): void
$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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function __invoke(ServerRequest $request): void
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'])
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct()

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

static::$twig = self::getTwigEnvironment($cacheDir);
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,13 @@ public static function parseQuery($query): array

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'
Expand Down
3 changes: 0 additions & 3 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator.RequiredNullSafeObjectOperator">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall.MissingTrailingComma">
<severity>4</severity>
</rule>
Expand Down

0 comments on commit b0bc4f4

Please sign in to comment.