Skip to content

Commit

Permalink
Remove dead code from Table\SearchController
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 Mar 9, 2024
1 parent 861dd4e commit 66916f3
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 113 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5000,21 +5000,11 @@ parameters:
count: 1
path: src/Controllers/Table/SearchController.php

-
message: "#^Parameter \\#1 \\$identifier of static method PhpMyAdmin\\\\Util\\:\\:backquote\\(\\) expects string\\|Stringable\\|null, mixed given\\.$#"
count: 2
path: src/Controllers/Table/SearchController.php

-
message: "#^Parameter \\#1 \\$params of static method PhpMyAdmin\\\\Url\\:\\:getCommon\\(\\) expects array\\<string, bool\\|int\\|string\\>, mixed given\\.$#"
count: 1
path: src/Controllers/Table/SearchController.php

-
message: "#^Parameter \\#1 \\$sqlQuery of static method PhpMyAdmin\\\\Core\\:\\:checkSqlQuerySignature\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Table/SearchController.php

-
message: "#^Parameter \\#1 \\$string of function strtoupper expects string, string\\|null given\\.$#"
count: 1
Expand All @@ -5035,11 +5025,6 @@ parameters:
count: 1
path: src/Controllers/Table/SearchController.php

-
message: "#^Parameter \\#2 \\$signature of static method PhpMyAdmin\\\\Core\\:\\:checkSqlQuerySignature\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Table/SearchController.php

-
message: "#^Parameter \\#3 \\$selectedOperator of method PhpMyAdmin\\\\Types\\:\\:getTypeOperatorsHtml\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
Expand Down
9 changes: 0 additions & 9 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3628,20 +3628,11 @@
</MixedAssignment>
<PossiblyInvalidArgument>
<code><![CDATA[$_POST['column']]]></code>
<code><![CDATA[$_POST['db']]]></code>
<code><![CDATA[$_POST['table']]]></code>
<code><![CDATA[$_POST['where_clause']]]></code>
<code><![CDATA[$_POST['where_clause_sign']]]></code>
<code><![CDATA[$selectedOperator]]></code>
</PossiblyInvalidArgument>
<PossiblyInvalidCast>
<code><![CDATA[$_POST['column']]]></code>
<code><![CDATA[$_POST['where_clause']]]></code>
<code><![CDATA[$_POST['where_clause_sign']]]></code>
</PossiblyInvalidCast>
<PossiblyInvalidOperand>
<code><![CDATA[$_POST['where_clause']]]></code>
</PossiblyInvalidOperand>
<PossiblyUnusedMethod>
<code><![CDATA[getColumnProperties]]></code>
</PossiblyUnusedMethod>
Expand Down
32 changes: 0 additions & 32 deletions src/Controllers/Table/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationCleanup;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Core;
use PhpMyAdmin\Current;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\DbTableExists;
Expand Down Expand Up @@ -223,37 +222,6 @@ public function __invoke(ServerRequest $request): void
}
}

/**
* Get data row action
*/
public function getDataRowAction(): void
{
if (! Core::checkSqlQuerySignature($_POST['where_clause'], $_POST['where_clause_sign'])) {
return;
}

$extraData = [];
$rowInfoQuery = 'SELECT * FROM ' . Util::backquote($_POST['db']) . '.'
. Util::backquote($_POST['table']) . ' WHERE ' . $_POST['where_clause'];
$result = $this->dbi->query($rowInfoQuery . ';');
$fieldsMeta = $this->dbi->getFieldsMeta($result);
while ($row = $result->fetchAssoc()) {
// for bit fields we need to convert them to printable form
$i = 0;
foreach ($row as $col => $val) {
if (isset($fieldsMeta[$i]) && $fieldsMeta[$i]->isMappedTypeBit) {
$row[$col] = Util::printableBitValue((int) $val, $fieldsMeta[$i]->length);
}

$i++;
}

$extraData['row_info'] = $row;
}

$this->response->addJSON($extraData);
}

/**
* Do selection action
*/
Expand Down
57 changes: 0 additions & 57 deletions tests/unit/Controllers/Table/SearchControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,17 @@
use PhpMyAdmin\Config;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\Table\SearchController;
use PhpMyAdmin\Core;
use PhpMyAdmin\Current;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\DbTableExists;
use PhpMyAdmin\Table\Search;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\FieldHelper;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseStub;
use PhpMyAdmin\Types;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;

use function hash;

use const MYSQLI_TYPE_LONG;

#[CoversClass(SearchController::class)]
class SearchControllerTest extends AbstractTestCase
{
Expand Down Expand Up @@ -106,55 +100,4 @@ public function testGetColumnMinMax(): void
$result = $ctrl->getColumnMinMax('column');
self::assertSame([$expected], $result);
}

/**
* Tests for getDataRowAction()
*/
public function testGetDataRowAction(): void
{
$dummyDbi = $this->createDbiDummy();
$dbi = $this->createDatabaseInterface($dummyDbi);
DatabaseInterface::$instance = $dbi;

$_SESSION[' HMAC_secret '] = hash('sha1', 'test');

$dummyDbi->addResult(
'SHOW FULL COLUMNS FROM `PMA`.`PMA_BookMark`',
[],
);

$dummyDbi->addResult(
'SHOW CREATE TABLE `PMA`.`PMA_BookMark`',
[],
);

$dummyDbi->addResult(
'SELECT * FROM `PMA`.`PMA_BookMark` WHERE `col1` = 1;',
[[1, 2]],
['col1', 'col2'],
[
FieldHelper::fromArray(['type' => MYSQLI_TYPE_LONG, 'length' => 11]),
FieldHelper::fromArray(['type' => MYSQLI_TYPE_LONG, 'length' => 11]),
],
);

$ctrl = new SearchController(
$this->response,
$this->template,
new Search($dbi),
new Relation($dbi),
$dbi,
new DbTableExists($dbi),
);

$_POST['db'] = 'PMA';
$_POST['table'] = 'PMA_BookMark';
$_POST['where_clause'] = '`col1` = 1';
$_POST['where_clause_sign'] = Core::signSqlQuery($_POST['where_clause']);
$expected = ['col1' => 1, 'col2' => 2];
$ctrl->getDataRowAction();

$json = $this->response->getJSONResult();
self::assertEquals($expected, $json['row_info']);
}
}

0 comments on commit 66916f3

Please sign in to comment.