Skip to content

Commit 01cb890

Browse files
Merge pull request #20026 from kamil-tekiela/Refactor-fetchRow
Refactor fetchRow()
2 parents 54c63ba + 271f468 commit 01cb890

File tree

8 files changed

+20
-41
lines changed

8 files changed

+20
-41
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13623,12 +13623,6 @@ parameters:
1362313623
count: 2
1362413624
path: src/Utils/Gis.php
1362513625

13626-
-
13627-
message: '#^Only booleans are allowed in an if condition, PhpMyAdmin\\Dbal\\ResultInterface\|false given\.$#'
13628-
identifier: if.condNotBoolean
13629-
count: 1
13630-
path: src/Utils/Gis.php
13631-
1363213626
-
1363313627
message: '''
1363413628
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:

psalm-baseline.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7705,14 +7705,12 @@
77057705
<code><![CDATA[$authenticationPlugin]]></code>
77067706
</PossiblyInvalidOperand>
77077707
<PossiblyNullArgument>
7708+
<code><![CDATA[$colName]]></code>
77087709
<code><![CDATA[$dbRightsRow['Db']]]></code>
77097710
<code><![CDATA[$row1['Type']]]></code>
77107711
<code><![CDATA[$row1['Type']]]></code>
77117712
<code><![CDATA[$row1['Type']]]></code>
77127713
<code><![CDATA[$row1['Type']]]></code>
7713-
<code><![CDATA[$row1[0]]]></code>
7714-
<code><![CDATA[$row1[0]]]></code>
7715-
<code><![CDATA[$row1[0]]]></code>
77167714
<code><![CDATA[$row1[1]]]></code>
77177715
<code><![CDATA[$row2['Column_priv']]]></code>
77187716
<code><![CDATA[$row['Db']]]></code>
@@ -7736,7 +7734,6 @@
77367734
<code><![CDATA[$dbRights[$row['User']]]]></code>
77377735
<code><![CDATA[$groupAssignment]]></code>
77387736
<code><![CDATA[$groupAssignment]]></code>
7739-
<code><![CDATA[$row]]></code>
77407737
</PossiblyNullArrayOffset>
77417738
<PossiblyNullOperand>
77427739
<code><![CDATA[$alterUserQuery]]></code>

src/ConfigStorage/UserGroups.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public static function getHtmlForListingUsersofAGroup(
5151
$result = $dbi->tryQueryAsControlUser($sqlQuery);
5252
if ($result) {
5353
$i = 0;
54-
while ($row = $result->fetchRow()) {
55-
$users[] = ['count' => ++$i, 'user' => $row[0]];
54+
foreach ($result->fetchAllColumn() as $value) {
55+
$users[] = ['count' => ++$i, 'user' => $value];
5656
}
5757
}
5858

src/Controllers/Server/UserGroupsFormController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ private function getHtmlToChooseUserGroup(
8787
$sqlQuery = 'SELECT DISTINCT `usergroup` FROM ' . $groupTable;
8888
$result = $this->dbi->tryQueryAsControlUser($sqlQuery);
8989
if ($result) {
90-
while ($row = $result->fetchRow()) {
91-
$allUserGroups[$row[0]] = $row[0];
90+
foreach ($result->fetchAllColumn() as $value) {
91+
$allUserGroups[$value] = $value;
9292
}
9393
}
9494

src/Database/Designer/Common.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ public function getScriptContr(array $designerTables): array
116116
$con = ['C_NAME' => [], 'DTN' => [], 'DCN' => [], 'STN' => [], 'SCN' => []];
117117
$i = 0;
118118
$allTabRs = $this->dbi->query('SHOW TABLES FROM ' . Util::backquote(Current::$database));
119-
while ($val = $allTabRs->fetchRow()) {
120-
$val = (string) $val[0];
121-
119+
/** @var string $val */
120+
foreach ($allTabRs->fetchAllColumn() as $val) {
122121
$row = $this->relation->getForeignersInternal(Current::$database, $val);
123122

124123
foreach ($row as $field => $value) {

src/Server/Privileges.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,13 @@ public function getHtmlToDisplayPrivilegesTable(
485485
$sqlQuery = 'SHOW COLUMNS FROM `mysql`.' . ($db === '*' ? '`user`' : '`db`') . ';';
486486

487487
$res = $this->dbi->query($sqlQuery);
488-
while ($row1 = $res->fetchRow()) {
489-
if (str_starts_with($row1[0], 'max_')) {
490-
$row[$row1[0]] = 0;
491-
} elseif (str_starts_with($row1[0], 'x509_') || str_starts_with($row1[0], 'ssl_')) {
492-
$row[$row1[0]] = '';
488+
foreach ($res->fetchAllColumn() as $colName) {
489+
if (str_starts_with($colName, 'max_')) {
490+
$row[$colName] = 0;
491+
} elseif (str_starts_with($colName, 'x509_') || str_starts_with($colName, 'ssl_')) {
492+
$row[$colName] = '';
493493
} else {
494-
$row[$row1[0]] = 'N';
494+
$row[$colName] = 'N';
495495
}
496496
}
497497
} elseif ($table === '*') {
@@ -514,8 +514,8 @@ public function getHtmlToDisplayPrivilegesTable(
514514
. '.' . Util::backquote($table) . ';',
515515
);
516516
if ($res) {
517-
while ($row1 = $res->fetchRow()) {
518-
$columns[$row1[0]] = [
517+
foreach ($res->fetchAllColumn() as $colName) {
518+
$columns[$colName] = [
519519
'Select' => false,
520520
'Insert' => false,
521521
'Update' => false,
@@ -1704,12 +1704,12 @@ public function getHtmlForAllTableSpecificRights(
17041704

17051705
$tables = [];
17061706
if ($result) {
1707-
while ($row = $result->fetchRow()) {
1708-
if (in_array($row[0], $foundRows, true)) {
1707+
foreach ($result->fetchAllColumn() as $tableName) {
1708+
if (in_array($tableName, $foundRows, true)) {
17091709
continue;
17101710
}
17111711

1712-
$tables[] = $row[0];
1712+
$tables[] = $tableName;
17131713
}
17141714
}
17151715

src/Utils/Gis.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ public static function convertToWellKnownText(string $data, bool $includeSRID =
4747
$wktsql .= ', ' . $spatialSrid . "(x'" . $hex . "')";
4848
}
4949

50-
$wktresult = $dbi->tryQuery($wktsql);
51-
$wktarr = [];
52-
if ($wktresult) {
53-
$wktarr = $wktresult->fetchRow();
54-
}
50+
$wktarr = $dbi->fetchSingleRow($wktsql);
5551

5652
$wktval = $wktarr[0] ?? '';
5753

tests/unit/Utils/GisTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use PhpMyAdmin\Dbal\DatabaseInterface;
88
use PhpMyAdmin\Tests\AbstractTestCase;
9-
use PhpMyAdmin\Tests\Stubs\DummyResult;
109
use PhpMyAdmin\Utils\Gis;
1110
use PHPUnit\Framework\Attributes\CoversClass;
1211
use PHPUnit\Framework\Attributes\DataProvider;
@@ -37,8 +36,6 @@ public function testConvertToWellKnownText(
3736
bool $SRIDOption,
3837
int $mysqlVersion,
3938
): void {
40-
$resultStub = self::createMock(DummyResult::class);
41-
4239
$dbi = $this->getMockBuilder(DatabaseInterface::class)
4340
->disableOriginalConstructor()
4441
->getMock();
@@ -48,12 +45,8 @@ public function testConvertToWellKnownText(
4845
->willReturn($mysqlVersion);
4946

5047
$dbi->expects($SRIDOption ? self::once() : self::exactly(2))
51-
->method('tryQuery')
48+
->method('fetchSingleRow')
5249
->with($expectedQuery)
53-
->willReturn($resultStub);// Omit the real object
54-
55-
$resultStub->expects($SRIDOption ? self::once() : self::exactly(2))
56-
->method('fetchRow')
5750
->willReturn($returnData);
5851

5952
DatabaseInterface::$instance = $dbi;

0 commit comments

Comments
 (0)