Better type hints

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2025-12-08 13:47:06 +00:00
parent f89ab9ecbf
commit 15ac2dec9b
4 changed files with 142 additions and 98 deletions

View File

@ -1966,41 +1966,47 @@ parameters:
path: src/Controllers/Database/Structure/RealRowCountController.php
-
message: '#^Binary operation "\*" between mixed and int results in an error\.$#'
message: '#^Binary operation "\*" between bool\|int\|string\|null and int results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Binary operation "\+" between \(float\|int\) and mixed results in an error\.$#'
message: '#^Binary operation "\*" between mixed and 2 results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Binary operation "\+" between mixed and mixed results in an error\.$#'
message: '#^Binary operation "\+" between \(float\|int\) and bool\|int\|string\|null results in an error\.$#'
identifier: binaryOp.invalid
count: 3
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Binary operation "\+\=" between \(float\|int\) and mixed results in an error\.$#'
message: '#^Binary operation "\+" between bool\|int\|string\|null and bool\|int\|string\|null results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Binary operation "\+" between int\|string\|null and int\|string\|null results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/Controllers/Database/StructureController.php
-
message: '#^Binary operation "\+\=" between int and int\<1, max\>\|string results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Binary operation "\+\=" between int and mixed results in an error\.$#'
message: '#^Binary operation "\+\=" between mixed and int\|string\|null results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Binary operation "\." between non\-falsy\-string and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Call to function array_search\(\) requires parameter \#3 to be set\.$#'
identifier: function.strict
@ -2014,11 +2020,35 @@ parameters:
path: src/Controllers/Database/StructureController.php
-
message: '#^Method PhpMyAdmin\\Controllers\\Database\\StructureController\:\:getStuffForEngineTypeTable\(\) should return array\{array\<mixed\>, string, string, string, string, int, bool, int\} but returns array\{non\-empty\-array, string, string, string, string, float\|int, bool, int\}\.$#'
message: '#^Method PhpMyAdmin\\Controllers\\Database\\StructureController\:\:getStuffForEngineTypeTable\(\) should return array\{array\<int\|string\|null\>, string, string, string, string, int, bool, int\} but returns array\{non\-empty\-array\<int\|string\|null\>, string, string, string, string, float\|int, bool, int\}\.$#'
identifier: return.type
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Method PhpMyAdmin\\Controllers\\Database\\StructureController\:\:getValuesForAriaTable\(\) should return array\{array\<int\|string\|null\>, string, string, string, string, float\|int, int\} but returns array\{array\<int\|string\|null\>, string, string, string, string, mixed, int\}\.$#'
identifier: return.type
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Method PhpMyAdmin\\Controllers\\Database\\StructureController\:\:getValuesForCsvTable\(\) should return array\{array\<int\|string\|null\>, string, string, int\} but returns array\{non\-empty\-array\<bool\|int\|string\|null\>, string, string, int\}\.$#'
identifier: return.type
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Method PhpMyAdmin\\Controllers\\Database\\StructureController\:\:getValuesForInnodbTable\(\) should return array\{array\<int\|string\|null\>, string, string, int\} but returns array\{non\-empty\-array\<bool\|int\|string\|null\>, string, string, int\}\.$#'
identifier: return.type
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Only booleans are allowed in a negated boolean, int\|string\|null given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
identifier: if.condNotBoolean
@ -2032,25 +2062,31 @@ parameters:
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, mixed given\.$#'
message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, bool\|int\|string\|null given\.$#'
identifier: argument.type
count: 3
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#1 \$str of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:quoteString\(\) expects string, mixed given\.$#'
message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, int\|string\|null given\.$#'
identifier: argument.type
count: 2
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, mixed given\.$#'
message: '#^Parameter \#1 \$str of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:quoteString\(\) expects string, bool\|int\|string\|null given\.$#'
identifier: argument.type
count: 2
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, int\|string\|null given\.$#'
identifier: argument.type
count: 4
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#1 \$string of function md5 expects string, mixed given\.$#'
message: '#^Parameter \#1 \$string of function md5 expects string, int\|string\|null given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Database/StructureController.php
@ -2062,7 +2098,7 @@ parameters:
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#1 \$table of method PhpMyAdmin\\Controllers\\Database\\StructureController\:\:getTrackingIcon\(\) expects string, mixed given\.$#'
message: '#^Parameter \#1 \$table of method PhpMyAdmin\\Controllers\\Database\\StructureController\:\:getTrackingIcon\(\) expects string, int\|string\|null given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Database/StructureController.php
@ -2073,12 +2109,6 @@ parameters:
count: 2
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Util\:\:formatByteDown\(\) expects float\|int\|string\|null, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#2 \$haystack of function array_search expects array, mixed given\.$#'
identifier: argument.type
@ -2086,26 +2116,26 @@ parameters:
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#2 \$table of method PhpMyAdmin\\Controllers\\Database\\StructureController\:\:getReplicationStatus\(\) expects string, mixed given\.$#'
message: '#^Parameter \#2 \$table of method PhpMyAdmin\\Controllers\\Database\\StructureController\:\:getReplicationStatus\(\) expects string, int\|string\|null given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#2 \$tableName of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:getTable\(\) expects string, mixed given\.$#'
message: '#^Parameter \#2 \$tableName of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:getTable\(\) expects string, int\|string\|null given\.$#'
identifier: argument.type
count: 5
count: 3
path: src/Controllers/Database/StructureController.php
-
message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Charsets\:\:findCollationByName\(\) expects string, mixed given\.$#'
message: '#^Parameter \#2 \$tableName of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:getTable\(\) expects string, int\|string\|true\|null given\.$#'
identifier: argument.type
count: 1
count: 2
path: src/Controllers/Database/StructureController.php
-
message: '#^Possibly invalid array key type mixed\.$#'
identifier: offsetAccess.invalidOffset
message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Charsets\:\:findCollationByName\(\) expects string, int\|string given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Database/StructureController.php
@ -14172,12 +14202,6 @@ parameters:
count: 1
path: src/Util.php
-
message: '#^Method PhpMyAdmin\\Util\:\:getDbInfo\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/Util.php
-
message: '#^Method PhpMyAdmin\\Util\:\:getTableListPosition\(\) should return int but returns mixed\.$#'
identifier: return.type

View File

@ -1135,6 +1135,18 @@
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/Database/StructureController.php">
<InvalidOperand>
<code><![CDATA[$currentTable['Data_free']]]></code>
<code><![CDATA[$currentTable['TABLE_ROWS']]]></code>
</InvalidOperand>
<InvalidReturnStatement>
<code><![CDATA[[$currentTable, $formattedSize, $unit, $sumSize]]]></code>
<code><![CDATA[[$currentTable, $formattedSize, $unit, $sumSize]]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[array{(string|int|null)[], string, string, int}]]></code>
<code><![CDATA[array{(string|int|null)[], string, string, int}]]></code>
</InvalidReturnType>
<LessSpecificReturnStatement>
<code><![CDATA[[
$currentTable,
@ -1146,11 +1158,37 @@
$tableIsView,
$sumSize,
]]]></code>
<code><![CDATA[[$currentTable, $formattedSize, $unit, $formattedOverhead, $overheadUnit, $overheadSize, $sumSize]]]></code>
</LessSpecificReturnStatement>
<MixedArgument>
<code><![CDATA[$dbTable]]></code>
<code><![CDATA[$replicaInfo['Do_DB']]]></code>
<code><![CDATA[$replicaInfo['Do_DB']]]></code>
<code><![CDATA[$replicaInfo['Do_DB']]]></code>
<code><![CDATA[$replicaInfo['Ignore_DB']]]></code>
<code><![CDATA[$replicaInfo['Ignore_DB']]]></code>
<code><![CDATA[$replicaInfo['Ignore_Table']]]></code>
<code><![CDATA[$replicaInfo['Wild_Do_Table']]]></code>
<code><![CDATA[$replicaInfo['Wild_Ignore_Table']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$charset]]></code>
<code><![CDATA[$dbTable]]></code>
<code><![CDATA[$searchDb]]></code>
<code><![CDATA[$searchDoDBInDB]]></code>
<code><![CDATA[$searchDoDBInTruename]]></code>
<code><![CDATA[$searchTable]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[getCharset]]></code>
</MixedMethodCall>
<MoreSpecificReturnType>
<code><![CDATA[list{(string|int|null)[], string, string, string, string, int, bool, int}]]></code>
</MoreSpecificReturnType>
<PossiblyFalseOperand>
<code><![CDATA[$columnNames]]></code>
</PossiblyFalseOperand>
<PossiblyInvalidArgument>
<code><![CDATA[$currentTable['Collation']]]></code>
<code><![CDATA[$currentTable['Data_free']]]></code>
<code><![CDATA[$currentTable['Name']]]></code>
<code><![CDATA[$currentTable['TABLE_COMMENT']]]></code>
<code><![CDATA[$currentTable['TABLE_NAME']]]></code>
@ -1166,58 +1204,44 @@
<code><![CDATA[$currentTable['TABLE_NAME']]]></code>
<code><![CDATA[$currentTable['TABLE_NAME']]]></code>
<code><![CDATA[$currentTable['TABLE_NAME']]]></code>
<code><![CDATA[$dbTable]]></code>
<code><![CDATA[$replicaInfo['Do_DB']]]></code>
<code><![CDATA[$replicaInfo['Do_DB']]]></code>
<code><![CDATA[$replicaInfo['Do_DB']]]></code>
<code><![CDATA[$replicaInfo['Ignore_DB']]]></code>
<code><![CDATA[$replicaInfo['Ignore_DB']]]></code>
<code><![CDATA[$replicaInfo['Ignore_Table']]]></code>
<code><![CDATA[$replicaInfo['Wild_Do_Table']]]></code>
<code><![CDATA[$replicaInfo['Wild_Ignore_Table']]]></code>
<code><![CDATA[$truename]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$charset]]></code>
<code><![CDATA[$dbTable]]></code>
<code><![CDATA[$overheadSize]]></code>
<code><![CDATA[$quotesLength]]></code>
<code><![CDATA[$searchDb]]></code>
<code><![CDATA[$searchDoDBInDB]]></code>
<code><![CDATA[$searchDoDBInTruename]]></code>
<code><![CDATA[$searchTable]]></code>
<code><![CDATA[$sumEntries]]></code>
<code><![CDATA[$truename]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[getCharset]]></code>
</MixedMethodCall>
<MixedOperand>
<code><![CDATA[$currentTable['Data_free']]]></code>
</PossiblyInvalidArgument>
<PossiblyInvalidOperand>
<code><![CDATA[$currentTable['Data_length']]]></code>
<code><![CDATA[$currentTable['Data_length']]]></code>
<code><![CDATA[$currentTable['Data_length']]]></code>
<code><![CDATA[$currentTable['TABLE_NAME']]]></code>
<code><![CDATA[$currentTable['Index_length']]]></code>
<code><![CDATA[$currentTable['Index_length']]]></code>
<code><![CDATA[$currentTable['Index_length']]]></code>
<code><![CDATA[$currentTable['TABLE_ROWS']]]></code>
<code><![CDATA[$currentTable['TABLE_ROWS']]]></code>
<code><![CDATA[$dataLength + $quotesLength]]></code>
<code><![CDATA[$quotesLength]]></code>
</MixedOperand>
<MoreSpecificReturnType>
<code><![CDATA[array{mixed[], string, string, string, string, int|float, int}]]></code>
<code><![CDATA[list{mixed[], string, string, string, string, int, bool, int}]]></code>
</MoreSpecificReturnType>
<PossiblyFalseOperand>
<code><![CDATA[$columnNames]]></code>
</PossiblyFalseOperand>
</PossiblyInvalidOperand>
<PossiblyNullOperand>
<code><![CDATA[$columnNames]]></code>
<code><![CDATA[$currentTable['Data_length']]]></code>
<code><![CDATA[$currentTable['Data_length']]]></code>
<code><![CDATA[$currentTable['Data_length']]]></code>
<code><![CDATA[$currentTable['Index_length']]]></code>
<code><![CDATA[$currentTable['Index_length']]]></code>
<code><![CDATA[$currentTable['Index_length']]]></code>
<code><![CDATA[$currentTable['TABLE_NAME']]]></code>
<code><![CDATA[$currentTable['TABLE_ROWS']]]></code>
<code><![CDATA[$currentTable['TABLE_ROWS']]]></code>
<code><![CDATA[$currentTable['TABLE_ROWS']]]></code>
</PossiblyNullOperand>
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$currentTable['TABLE_ROWS']]]></code>
</PossiblyUndefinedArrayOffset>
<RiskyTruthyFalsyComparison>
<code><![CDATA[! $currentTable['COUNTED']]]></code>
</RiskyTruthyFalsyComparison>
<UnnecessaryVarAnnotation>
<code><![CDATA[int]]></code>
<code><![CDATA[int]]></code>
<code><![CDATA[int]]></code>
<code><![CDATA[int]]></code>
</UnnecessaryVarAnnotation>
</file>
<file src="src/Controllers/Database/TrackingController.php">
<MixedArgument>

View File

@ -72,7 +72,7 @@ final class StructureController implements InvocableController
/** @var int Number of tables */
private int $totalNumTables = 0;
/** @var mixed[] Tables in the database */
/** @var (string|int|null)[][] Tables in the database */
private array $tables = [];
/** @var bool whether stats show or not */
@ -231,7 +231,6 @@ final class StructureController implements InvocableController
$structureTableRows = [];
$trackedTables = $this->trackingChecker->getTrackedTables(Current::$database);
$recentFavoriteTables = RecentFavoriteTables::getInstance(TableType::Favorite);
/** @var mixed[] $currentTable */
foreach ($this->tables as $currentTable) {
// Get valid statistics whatever is the table type
@ -255,8 +254,7 @@ final class StructureController implements InvocableController
$sumSize,
] = $this->getStuffForEngineTypeTable($currentTable, $sumSize, $overheadSize);
$curTable = $this->dbi
->getTable(Current::$database, $currentTable['TABLE_NAME']);
$curTable = $this->dbi->getTable(Current::$database, $currentTable['TABLE_NAME']);
if (! $curTable->isMerge()) {
$sumEntries += $currentTable['TABLE_ROWS'];
}
@ -535,8 +533,8 @@ final class StructureController implements InvocableController
/**
* Returns whether the row count is approximated
*
* @param mixed[] $currentTable array containing details about the table
* @param bool $tableIsView whether the table is a view
* @param (string|int|null)[] $currentTable array containing details about the table
* @param bool $tableIsView whether the table is a view
*
* @return array{bool, string}
*/
@ -641,11 +639,11 @@ final class StructureController implements InvocableController
*
* @internal param bool $table_is_view whether table is view or not
*
* @param mixed[] $currentTable current table
* @param (string|int|null)[] $currentTable current table
* @param int $sumSize total table size
* @param int $overheadSize overhead size
*
* @psalm-return list{mixed[], string, string, string, string, int, bool, int}
* @return list{(string|int|null)[], string, string, string, string, int, bool, int}
*/
private function getStuffForEngineTypeTable(
array $currentTable,
@ -760,7 +758,7 @@ final class StructureController implements InvocableController
/**
* Get values for ARIA/MARIA tables
*
* @param mixed[] $currentTable current table
* @param (string|int|null)[] $currentTable current table
* @param int $sumSize sum size
* @param int $overheadSize overhead size
* @param string $formattedSize formatted size
@ -768,7 +766,7 @@ final class StructureController implements InvocableController
* @param string $formattedOverhead overhead formatted
* @param string $overheadUnit overhead unit
*
* @return array{mixed[], string, string, string, string, int|float, int}
* @return array{(string|int|null)[], string, string, string, string, int|float, int}
*/
private function getValuesForAriaTable(
array $currentTable,
@ -787,8 +785,7 @@ final class StructureController implements InvocableController
if ($this->isShowStats) {
/** @var int $tblsize */
$tblsize = $currentTable['Data_length']
+ $currentTable['Index_length'];
$tblsize = $currentTable['Data_length'] + $currentTable['Index_length'];
$sumSize += $tblsize;
[$formattedSize, $unit] = Util::formatByteDown($tblsize, 3, $tblsize > 0 ? 1 : 0);
if (isset($currentTable['Data_free']) && $currentTable['Data_free'] > 0) {
@ -803,10 +800,10 @@ final class StructureController implements InvocableController
/**
* Get values for InnoDB table
*
* @param mixed[] $currentTable current table
* @param (string|int|null)[] $currentTable current table
* @param int $sumSize sum size
*
* @return array{mixed[], string, string, int}
* @return array{(string|int|null)[], string, string, int}
*/
private function getValuesForInnodbTable(
array $currentTable,
@ -843,9 +840,9 @@ final class StructureController implements InvocableController
*
* https://bugs.mysql.com/bug.php?id=53929
*
* @param mixed[] $currentTable
* @param (string|int|null)[] $currentTable
*
* @return array{mixed[], string, string, int}
* @return array{(string|int|null)[], string, string, int}
*/
private function getValuesForCsvTable(array $currentTable, int $sumSize): array
{
@ -902,10 +899,10 @@ final class StructureController implements InvocableController
/**
* Get values for Mroonga table
*
* @param mixed[] $currentTable current table
* @param (string|int|null)[] $currentTable current table
* @param int $sumSize sum size
*
* @return array{mixed[], string, string, int}
* @return array{(string|int|null)[], string, string, int}
*/
private function getValuesForMroongaTable(
array $currentTable,

View File

@ -1486,8 +1486,7 @@ class Util
/**
* Gets the list of tables in the current db and information about these tables if possible.
*
* @return array<int, array|int>
* @psalm-return array{array, int}
* @return array{(string|int|null)[][], int}
*/
public static function getDbInfo(ServerRequest $request, string $db, bool $isResultLimited = true): array
{
@ -1604,7 +1603,7 @@ class Util
* Gets the list of tables in the current db, taking into account
* that they might be "in use"
*
* @return mixed[] list of tables
* @return (string|int|null)[][] list of tables
*/
private static function getTablesWhenOpen(string $db): array
{