Skip to content

Commit

Permalink
Merge pull request #18631 from kamil-tekiela/Use-null-coalescing-returns
Browse files Browse the repository at this point in the history
Use null-coalescing returns
  • Loading branch information
MauricioFauth committed Aug 17, 2023
2 parents 5b5e444 + 2accd4c commit 8279057
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 28 deletions.
6 changes: 1 addition & 5 deletions libraries/classes/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ public static function getFromTable(DatabaseInterface $dbi, string $table, strin
{
self::loadIndexes($dbi, $table, $schema);

if (isset(self::$registry[$schema][$table])) {
return self::$registry[$schema][$table];
}

return [];
return self::$registry[$schema][$table] ?? [];
}

/**
Expand Down
6 changes: 1 addition & 5 deletions libraries/classes/InsertEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,7 @@ public function getGotoInclude(string|false $gotoInclude): string
*/
public function getErrorUrl(array $urlParams): string
{
if (isset($_POST['err_url'])) {
return $_POST['err_url'];
}

return Url::getFromRoute('/table/change', $urlParams);
return $_POST['err_url'] ?? Url::getFromRoute('/table/change', $urlParams);
}

/**
Expand Down
12 changes: 2 additions & 10 deletions libraries/classes/LanguageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,8 @@ public function getLanguage(string $code): Language|false
{
$code = strtolower($code);
$langs = $this->availableLanguages();
if (isset($langs[$code])) {
return $langs[$code];
}

return false;
return $langs[$code] ?? false;
}

/**
Expand Down Expand Up @@ -948,13 +945,8 @@ public function selectLanguage(): Language
}
}

// Didn't catch any valid lang : we use the default settings
if (isset($langs[$config->get('DefaultLang')])) {
return $langs[$config->get('DefaultLang')];
}

// Fallback to English
return $langs['en'];
return $langs[$config->get('DefaultLang')] ?? $langs['en'];
}

/**
Expand Down
6 changes: 1 addition & 5 deletions libraries/classes/Navigation/Nodes/NodeDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ public function __construct(string $name, int $type = Node::OBJECT, bool $isGrou
*/
public function getPresence(string $type = '', string $searchClause = ''): int
{
if (isset($this->presenceCounts[$type][$searchClause])) {
return $this->presenceCounts[$type][$searchClause];
}

return $this->presenceCounts[$type][$searchClause] = match ($type) {
return $this->presenceCounts[$type][$searchClause] ??= match ($type) {

Check warning on line 75 in libraries/classes/Navigation/Nodes/NodeDatabase.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "MatchArmRemoval": --- Original +++ New @@ @@ { return $this->presenceCounts[$type][$searchClause] ??= match ($type) { 'tables' => $this->getTableCount($searchClause), - 'views' => $this->getViewCount($searchClause), 'procedures' => $this->getProcedureCount($searchClause), 'functions' => $this->getFunctionCount($searchClause), 'events' => $this->getEventCount($searchClause),

Check warning on line 75 in libraries/classes/Navigation/Nodes/NodeDatabase.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "MatchArmRemoval": --- Original +++ New @@ @@ return $this->presenceCounts[$type][$searchClause] ??= match ($type) { 'tables' => $this->getTableCount($searchClause), 'views' => $this->getViewCount($searchClause), - 'procedures' => $this->getProcedureCount($searchClause), 'functions' => $this->getFunctionCount($searchClause), 'events' => $this->getEventCount($searchClause), default => 0,

Check warning on line 75 in libraries/classes/Navigation/Nodes/NodeDatabase.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "MatchArmRemoval": --- Original +++ New @@ @@ 'views' => $this->getViewCount($searchClause), 'procedures' => $this->getProcedureCount($searchClause), 'functions' => $this->getFunctionCount($searchClause), - 'events' => $this->getEventCount($searchClause), default => 0, }; }

Check warning on line 75 in libraries/classes/Navigation/Nodes/NodeDatabase.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "MatchArmRemoval": --- Original +++ New @@ @@ 'procedures' => $this->getProcedureCount($searchClause), 'functions' => $this->getFunctionCount($searchClause), 'events' => $this->getEventCount($searchClause), - default => 0, }; } /**

Check warning on line 75 in libraries/classes/Navigation/Nodes/NodeDatabase.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "AssignCoalesce": --- Original +++ New @@ @@ */ public function getPresence(string $type = '', string $searchClause = '') : int { - return $this->presenceCounts[$type][$searchClause] ??= match ($type) { + return $this->presenceCounts[$type][$searchClause] = match ($type) { 'tables' => $this->getTableCount($searchClause), 'views' => $this->getViewCount($searchClause), 'procedures' => $this->getProcedureCount($searchClause),
'tables' => $this->getTableCount($searchClause),
'views' => $this->getViewCount($searchClause),
'procedures' => $this->getProcedureCount($searchClause),
Expand Down
4 changes: 1 addition & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6932,7 +6932,7 @@
<code><![CDATA[$GLOBALS['cfg']['UploadDir']]]></code>
</InvalidArrayOffset>
<InvalidReturnStatement>
<code><![CDATA[$_POST['err_url']]]></code>
<code><![CDATA[$_POST['err_url'] ?? Url::getFromRoute('/table/change', $urlParams)]]></code>
<code>$formParams</code>
</InvalidReturnStatement>
<InvalidReturnType>
Expand Down Expand Up @@ -7091,11 +7091,9 @@
</MixedArgumentTypeCoercion>
<MixedArrayOffset>
<code><![CDATA[$langs[$config->get('DefaultLang')]]]></code>
<code><![CDATA[$langs[$config->get('DefaultLang')]]]></code>
</MixedArrayOffset>
<MixedArrayTypeCoercion>
<code><![CDATA[$langs[$config->get('DefaultLang')]]]></code>
<code><![CDATA[$langs[$config->get('DefaultLang')]]]></code>
</MixedArrayTypeCoercion>
<MixedAssignment>
<code>$lang</code>
Expand Down

0 comments on commit 8279057

Please sign in to comment.