Skip to content

Commit

Permalink
Fix issues with wrong type provided for $table
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 7b95a4b commit 63b59f2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
17 changes: 7 additions & 10 deletions libraries/classes/Menu.php
Expand Up @@ -18,7 +18,6 @@
use function mb_strstr;
use function mb_substr;
use function preg_replace;
use function strlen;

/**
* Class for generating the top menu
Expand Down Expand Up @@ -67,10 +66,8 @@ public function __construct(DatabaseInterface $dbi, string $db, string $table)

/**
* Returns the menu and the breadcrumbs as a string
*
* @return string
*/
public function getDisplay()
public function getDisplay(): string
{
$retval = $this->getBreadcrumbs();
$retval .= $this->getMenu();
Expand Down Expand Up @@ -182,10 +179,10 @@ private function getBreadcrumbs(): string
? '' : ':' . $cfg['Server']['port'];
$server['url'] = Util::getUrlForOption($cfg['DefaultTabServer'], 'server');

if (strlen($this->db) > 0) {
if ($this->db !== '') {
$database['name'] = $this->db;
$database['url'] = Util::getUrlForOption($cfg['DefaultTabDatabase'], 'database');
if (strlen((string) $this->table) > 0) {
if ($this->table !== '') {
$table['name'] = $this->table;
$table['url'] = Util::getUrlForOption($cfg['DefaultTabTable'], 'table');
$tableObj = $this->dbi->getTable($this->db, $this->table);
Expand Down Expand Up @@ -222,7 +219,7 @@ private function getBreadcrumbs(): string
*
* @return array Data for generating table tabs
*/
private function getTableTabs()
private function getTableTabs(): array
{
global $route;

Expand Down Expand Up @@ -344,7 +341,7 @@ private function getTableTabs()
*
* @return array Data for generating db tabs
*/
private function getDbTabs()
private function getDbTabs(): array
{
global $route;

Expand Down Expand Up @@ -461,7 +458,7 @@ private function getDbTabs()
*
* @return array Data for generating server tabs
*/
private function getServerTabs()
private function getServerTabs(): array
{
global $route;

Expand Down Expand Up @@ -583,7 +580,7 @@ private function getServerTabs()
*
* @return Menu
*/
public function setTable($table)
public function setTable(string $table)
{
$this->table = $table;

Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Sql.php
Expand Up @@ -821,7 +821,7 @@ private function executeTheQuery(
$extraData
) {
$response = ResponseRenderer::getInstance();
$response->getHeader()->getMenu()->setTable($table);
$response->getHeader()->getMenu()->setTable($table ?? '');

// Only if we ask to see the php code
if (isset($GLOBALS['show_as_php'])) {
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Expand Up @@ -1230,11 +1230,6 @@ parameters:
count: 1
path: libraries/classes/Sql.php

-
message: "#^Parameter \\#1 \\$table of method PhpMyAdmin\\\\Menu\\:\\:setTable\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: libraries/classes/Sql.php

-
message: "#^Parameter \\#2 \\$error of method PhpMyAdmin\\\\Sql\\:\\:handleQueryExecuteError\\(\\) expects string, string\\|true given\\.$#"
count: 1
Expand Down
3 changes: 0 additions & 3 deletions psalm-baseline.xml
Expand Up @@ -8577,9 +8577,6 @@
<PossiblyNullArrayAccess occurrences="1">
<code>$allowedTabs[$tabName]</code>
</PossiblyNullArrayAccess>
<RedundantCastGivenDocblockType occurrences="1">
<code>(string) $this-&gt;table</code>
</RedundantCastGivenDocblockType>
</file>
<file src="libraries/classes/Message.php">
<DocblockTypeContradiction occurrences="1">
Expand Down

0 comments on commit 63b59f2

Please sign in to comment.