Skip to content

Commit

Permalink
Refactor getMenu() method
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
  • Loading branch information
kamil-tekiela committed Nov 28, 2021
1 parent 66e1357 commit b604a86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
17 changes: 5 additions & 12 deletions libraries/classes/Menu.php
Expand Up @@ -11,7 +11,7 @@
use PhpMyAdmin\Utils\SessionCache;

use function __;
use function array_key_exists;
use function array_intersect_key;
use function count;
use function in_array;
use function mb_strpos;
Expand Down Expand Up @@ -84,15 +84,13 @@ private function getMenu(): string
{
$urlParams = [];

$hasDbArg = strlen($this->db) > 0;

// The URL will not work if the table is defined without a database
if (strlen((string) $this->table) > 0 && $hasDbArg) {
if ($this->table !== '' && $this->db !== '') {
$tabs = $this->getTableTabs();
$urlParams['db'] = $this->db;
$urlParams['table'] = $this->table;
$level = 'table';
} elseif ($hasDbArg) {
} elseif ($this->db !== '') {
$tabs = $this->getDbTabs();
$urlParams['db'] = $this->db;
$level = 'db';
Expand All @@ -102,13 +100,8 @@ private function getMenu(): string
}

$allowedTabs = $this->getAllowedTabs($level);
foreach ($tabs as $key => $value) {
if (array_key_exists($key, $allowedTabs)) {
continue;
}

unset($tabs[$key]);
}
// Filter out any tabs that are not allowed
$tabs = array_intersect_key($tabs, $allowedTabs);

return $this->template->render('top_menu', [
'tabs' => $tabs,
Expand Down
9 changes: 2 additions & 7 deletions psalm-baseline.xml
Expand Up @@ -8554,10 +8554,9 @@
<code>$row['tab']</code>
<code>$row['tab']</code>
</MixedArgument>
<MixedAssignment occurrences="3">
<MixedAssignment occurrences="2">
<code>$binaryLogs</code>
<code>$result</code>
<code>$value</code>
</MixedAssignment>
<MixedInferredReturnType occurrences="1">
<code>array</code>
Expand All @@ -8578,13 +8577,9 @@
<PossiblyNullArrayAccess occurrences="1">
<code>$allowedTabs[$tabName]</code>
</PossiblyNullArrayAccess>
<RedundantCastGivenDocblockType occurrences="2">
<code>(string) $this-&gt;table</code>
<RedundantCastGivenDocblockType occurrences="1">
<code>(string) $this-&gt;table</code>
</RedundantCastGivenDocblockType>
<UnusedForeachValue occurrences="1">
<code>$value</code>
</UnusedForeachValue>
</file>
<file src="libraries/classes/Message.php">
<DocblockTypeContradiction occurrences="1">
Expand Down

0 comments on commit b604a86

Please sign in to comment.