Merge pull request #20026 from kamil-tekiela/Refactor-fetchRow

Refactor fetchRow()
This commit is contained in:
Maurício Meneghini Fauth 2026-01-16 19:34:13 -03:00 committed by GitHub
commit 01cb890f61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 20 additions and 41 deletions

View File

@ -13623,12 +13623,6 @@ parameters:
count: 2
path: src/Utils/Gis.php
-
message: '#^Only booleans are allowed in an if condition, PhpMyAdmin\\Dbal\\ResultInterface\|false given\.$#'
identifier: if.condNotBoolean
count: 1
path: src/Utils/Gis.php
-
message: '''
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:

View File

@ -7705,14 +7705,12 @@
<code><![CDATA[$authenticationPlugin]]></code>
</PossiblyInvalidOperand>
<PossiblyNullArgument>
<code><![CDATA[$colName]]></code>
<code><![CDATA[$dbRightsRow['Db']]]></code>
<code><![CDATA[$row1['Type']]]></code>
<code><![CDATA[$row1['Type']]]></code>
<code><![CDATA[$row1['Type']]]></code>
<code><![CDATA[$row1['Type']]]></code>
<code><![CDATA[$row1[0]]]></code>
<code><![CDATA[$row1[0]]]></code>
<code><![CDATA[$row1[0]]]></code>
<code><![CDATA[$row1[1]]]></code>
<code><![CDATA[$row2['Column_priv']]]></code>
<code><![CDATA[$row['Db']]]></code>
@ -7736,7 +7734,6 @@
<code><![CDATA[$dbRights[$row['User']]]]></code>
<code><![CDATA[$groupAssignment]]></code>
<code><![CDATA[$groupAssignment]]></code>
<code><![CDATA[$row]]></code>
</PossiblyNullArrayOffset>
<PossiblyNullOperand>
<code><![CDATA[$alterUserQuery]]></code>

View File

@ -51,8 +51,8 @@ class UserGroups
$result = $dbi->tryQueryAsControlUser($sqlQuery);
if ($result) {
$i = 0;
while ($row = $result->fetchRow()) {
$users[] = ['count' => ++$i, 'user' => $row[0]];
foreach ($result->fetchAllColumn() as $value) {
$users[] = ['count' => ++$i, 'user' => $value];
}
}

View File

@ -87,8 +87,8 @@ final class UserGroupsFormController implements InvocableController
$sqlQuery = 'SELECT DISTINCT `usergroup` FROM ' . $groupTable;
$result = $this->dbi->tryQueryAsControlUser($sqlQuery);
if ($result) {
while ($row = $result->fetchRow()) {
$allUserGroups[$row[0]] = $row[0];
foreach ($result->fetchAllColumn() as $value) {
$allUserGroups[$value] = $value;
}
}

View File

@ -116,9 +116,8 @@ class Common
$con = ['C_NAME' => [], 'DTN' => [], 'DCN' => [], 'STN' => [], 'SCN' => []];
$i = 0;
$allTabRs = $this->dbi->query('SHOW TABLES FROM ' . Util::backquote(Current::$database));
while ($val = $allTabRs->fetchRow()) {
$val = (string) $val[0];
/** @var string $val */
foreach ($allTabRs->fetchAllColumn() as $val) {
$row = $this->relation->getForeignersInternal(Current::$database, $val);
foreach ($row as $field => $value) {

View File

@ -485,13 +485,13 @@ class Privileges
$sqlQuery = 'SHOW COLUMNS FROM `mysql`.' . ($db === '*' ? '`user`' : '`db`') . ';';
$res = $this->dbi->query($sqlQuery);
while ($row1 = $res->fetchRow()) {
if (str_starts_with($row1[0], 'max_')) {
$row[$row1[0]] = 0;
} elseif (str_starts_with($row1[0], 'x509_') || str_starts_with($row1[0], 'ssl_')) {
$row[$row1[0]] = '';
foreach ($res->fetchAllColumn() as $colName) {
if (str_starts_with($colName, 'max_')) {
$row[$colName] = 0;
} elseif (str_starts_with($colName, 'x509_') || str_starts_with($colName, 'ssl_')) {
$row[$colName] = '';
} else {
$row[$row1[0]] = 'N';
$row[$colName] = 'N';
}
}
} elseif ($table === '*') {
@ -514,8 +514,8 @@ class Privileges
. '.' . Util::backquote($table) . ';',
);
if ($res) {
while ($row1 = $res->fetchRow()) {
$columns[$row1[0]] = [
foreach ($res->fetchAllColumn() as $colName) {
$columns[$colName] = [
'Select' => false,
'Insert' => false,
'Update' => false,
@ -1704,12 +1704,12 @@ class Privileges
$tables = [];
if ($result) {
while ($row = $result->fetchRow()) {
if (in_array($row[0], $foundRows, true)) {
foreach ($result->fetchAllColumn() as $tableName) {
if (in_array($tableName, $foundRows, true)) {
continue;
}
$tables[] = $row[0];
$tables[] = $tableName;
}
}

View File

@ -47,11 +47,7 @@ final class Gis
$wktsql .= ', ' . $spatialSrid . "(x'" . $hex . "')";
}
$wktresult = $dbi->tryQuery($wktsql);
$wktarr = [];
if ($wktresult) {
$wktarr = $wktresult->fetchRow();
}
$wktarr = $dbi->fetchSingleRow($wktsql);
$wktval = $wktarr[0] ?? '';

View File

@ -6,7 +6,6 @@ namespace PhpMyAdmin\Tests\Utils;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DummyResult;
use PhpMyAdmin\Utils\Gis;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
@ -37,8 +36,6 @@ class GisTest extends AbstractTestCase
bool $SRIDOption,
int $mysqlVersion,
): void {
$resultStub = self::createMock(DummyResult::class);
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
@ -48,12 +45,8 @@ class GisTest extends AbstractTestCase
->willReturn($mysqlVersion);
$dbi->expects($SRIDOption ? self::once() : self::exactly(2))
->method('tryQuery')
->method('fetchSingleRow')
->with($expectedQuery)
->willReturn($resultStub);// Omit the real object
$resultStub->expects($SRIDOption ? self::once() : self::exactly(2))
->method('fetchRow')
->willReturn($returnData);
DatabaseInterface::$instance = $dbi;