diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 20f67c43d3..317b590563 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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\: diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 33d87ad891..5ecfb6a289 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7705,14 +7705,12 @@ + - - - @@ -7736,7 +7734,6 @@ - diff --git a/src/ConfigStorage/UserGroups.php b/src/ConfigStorage/UserGroups.php index a1040c03dc..502e843cef 100644 --- a/src/ConfigStorage/UserGroups.php +++ b/src/ConfigStorage/UserGroups.php @@ -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]; } } diff --git a/src/Controllers/Server/UserGroupsFormController.php b/src/Controllers/Server/UserGroupsFormController.php index dcb4a3cbd7..5bb651a5a7 100644 --- a/src/Controllers/Server/UserGroupsFormController.php +++ b/src/Controllers/Server/UserGroupsFormController.php @@ -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; } } diff --git a/src/Database/Designer/Common.php b/src/Database/Designer/Common.php index f4e768543b..e358ca8ab2 100644 --- a/src/Database/Designer/Common.php +++ b/src/Database/Designer/Common.php @@ -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) { diff --git a/src/Server/Privileges.php b/src/Server/Privileges.php index fa6acdd767..2a8c67aff1 100644 --- a/src/Server/Privileges.php +++ b/src/Server/Privileges.php @@ -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; } } diff --git a/src/Utils/Gis.php b/src/Utils/Gis.php index b233074ac5..59938dd6cc 100644 --- a/src/Utils/Gis.php +++ b/src/Utils/Gis.php @@ -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] ?? ''; diff --git a/tests/unit/Utils/GisTest.php b/tests/unit/Utils/GisTest.php index 7d05da9340..e23feb06be 100644 --- a/tests/unit/Utils/GisTest.php +++ b/tests/unit/Utils/GisTest.php @@ -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;