Skip to content

Commit

Permalink
Better array types in Normalization
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
  • Loading branch information
kamil-tekiela committed Mar 7, 2023
1 parent 98beb5b commit 1aa7cc1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 38 deletions.
16 changes: 8 additions & 8 deletions libraries/classes/Normalization.php
Expand Up @@ -1027,18 +1027,18 @@ private function checkPartialDependency(
/**
* function to get distinct values count of all the column in the array $columns
*
* @param array $columns array of backquoted columns whose distinct values
* need to be counted.
* @param string $table table to which these columns belong
* @param string[] $columns array of backquoted columns whose distinct values
* need to be counted.
* @param string $table table to which these columns belong
*
* @return array associative array containing the count
* @return int[] associative array containing the count
*/
private function findDistinctValuesCount(array $columns, $table): array
{
$result = [];
$query = 'SELECT ';
foreach ($columns as $column) {
if (! $column) {
if ($column === '') {
continue;
}

Expand All @@ -1052,11 +1052,11 @@ private function findDistinctValuesCount(array $columns, $table): array
. ' LIMIT 500) as dt;';
$res = $this->dbi->fetchResult($query, null, null);
foreach ($columns as $column) {
if (! $column) {
if ($column === '') {
continue;
}

$result[$column] = $res[0][$column . '_cnt'] ?? null;
$result[$column] = (int) $res[0][$column . '_cnt'];
}

return $result;
Expand All @@ -1067,7 +1067,7 @@ private function findDistinctValuesCount(array $columns, $table): array
*
* @param array $primaryKey array containing all the column present in primary key
*
* @return array containing all the possible partial keys(subset of primary key)
* @return string[] containing all the possible partial keys(subset of primary key)
*/
private function getAllCombinationPartialKeys(array $primaryKey): array
{
Expand Down
20 changes: 5 additions & 15 deletions phpstan-baseline.neon
Expand Up @@ -5730,6 +5730,11 @@ parameters:
count: 1
path: libraries/classes/Navigation/Nodes/NodeTable.php

-
message: "#^Casting to string something that's already string\\.$#"
count: 1
path: libraries/classes/Normalization.php

-
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:createNewTablesFor2NF\\(\\) has parameter \\$partialDependencies with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -5755,26 +5760,11 @@ parameters:
count: 1
path: libraries/classes/Normalization.php

-
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:findDistinctValuesCount\\(\\) has parameter \\$columns with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Normalization.php

-
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:findDistinctValuesCount\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Normalization.php

-
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:getAllCombinationPartialKeys\\(\\) has parameter \\$primaryKey with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Normalization.php

-
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:getAllCombinationPartialKeys\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Normalization.php

-
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:getHtmlFor3NFstep1\\(\\) has parameter \\$tables with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
18 changes: 3 additions & 15 deletions psalm-baseline.xml
Expand Up @@ -8977,12 +8977,9 @@
<code>$dependents</code>
<code>$dependents</code>
<code>$dependents</code>
<code>$distinctValCount[$column]</code>
<code>$distinctValCount[$partialKey]</code>
<code><![CDATA[$dropCols['nonpk']]]></code>
<code><![CDATA[$dropCols['pk']]]></code>
<code>$key</code>
<code>$partialKey</code>
<code>$table</code>
<code>$table</code>
<code>$table</code>
Expand Down Expand Up @@ -9012,37 +9009,25 @@
<code><![CDATA[$dropCols['pk']]]></code>
<code><![CDATA[$res[0][$column . '_cnt']]]></code>
</MixedArrayAccess>
<MixedArrayOffset>
<code>$dependencyList[$partialKey]</code>
<code>$distinctValCount[$partialKey]</code>
<code>$result[$column]</code>
</MixedArrayOffset>
<MixedAssignment>
<code>$arrDependson</code>
<code>$col</code>
<code>$cols</code>
<code>$column</code>
<code>$column</code>
<code>$dependent</code>
<code>$dependents</code>
<code>$dependents</code>
<code>$dependents</code>
<code>$dropCols</code>
<code>$element</code>
<code>$key</code>
<code>$partialKey</code>
<code>$pkColCnt</code>
<code>$result[$column]</code>
<code>$table</code>
<code>$table</code>
<code>$tablesList</code>
<code>$totalRows</code>
<code>$type</code>
</MixedAssignment>
<MixedOperand>
<code>$column</code>
<code>$column</code>
<code>$column</code>
<code>$element</code>
</MixedOperand>
<PossiblyNullArgument>
Expand All @@ -9053,6 +9038,9 @@
<code><![CDATA[$def['Type']]]></code>
<code><![CDATA[$def['Type']]]></code>
</PossiblyUndefinedArrayOffset>
<RedundantCast>
<code>(string) $dependon</code>
</RedundantCast>
</file>
<file src="libraries/classes/Operations.php">
<DeprecatedMethod>
Expand Down

0 comments on commit 1aa7cc1

Please sign in to comment.