Skip to content

Commit 27af8d2

Browse files
Merge pull request #18167 from kamil-tekiela/Better-array-types-3
Better array types in Normalization
2 parents 98beb5b + 1aa7cc1 commit 27af8d2

File tree

3 files changed

+16
-38
lines changed

3 files changed

+16
-38
lines changed

libraries/classes/Normalization.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,18 +1027,18 @@ private function checkPartialDependency(
10271027
/**
10281028
* function to get distinct values count of all the column in the array $columns
10291029
*
1030-
* @param array $columns array of backquoted columns whose distinct values
1031-
* need to be counted.
1032-
* @param string $table table to which these columns belong
1030+
* @param string[] $columns array of backquoted columns whose distinct values
1031+
* need to be counted.
1032+
* @param string $table table to which these columns belong
10331033
*
1034-
* @return array associative array containing the count
1034+
* @return int[] associative array containing the count
10351035
*/
10361036
private function findDistinctValuesCount(array $columns, $table): array
10371037
{
10381038
$result = [];
10391039
$query = 'SELECT ';
10401040
foreach ($columns as $column) {
1041-
if (! $column) {
1041+
if ($column === '') {
10421042
continue;
10431043
}
10441044

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

1059-
$result[$column] = $res[0][$column . '_cnt'] ?? null;
1059+
$result[$column] = (int) $res[0][$column . '_cnt'];
10601060
}
10611061

10621062
return $result;
@@ -1067,7 +1067,7 @@ private function findDistinctValuesCount(array $columns, $table): array
10671067
*
10681068
* @param array $primaryKey array containing all the column present in primary key
10691069
*
1070-
* @return array containing all the possible partial keys(subset of primary key)
1070+
* @return string[] containing all the possible partial keys(subset of primary key)
10711071
*/
10721072
private function getAllCombinationPartialKeys(array $primaryKey): array
10731073
{

phpstan-baseline.neon

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5730,6 +5730,11 @@ parameters:
57305730
count: 1
57315731
path: libraries/classes/Navigation/Nodes/NodeTable.php
57325732

5733+
-
5734+
message: "#^Casting to string something that's already string\\.$#"
5735+
count: 1
5736+
path: libraries/classes/Normalization.php
5737+
57335738
-
57345739
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:createNewTablesFor2NF\\(\\) has parameter \\$partialDependencies with no value type specified in iterable type array\\.$#"
57355740
count: 1
@@ -5755,26 +5760,11 @@ parameters:
57555760
count: 1
57565761
path: libraries/classes/Normalization.php
57575762

5758-
-
5759-
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:findDistinctValuesCount\\(\\) has parameter \\$columns with no value type specified in iterable type array\\.$#"
5760-
count: 1
5761-
path: libraries/classes/Normalization.php
5762-
5763-
-
5764-
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:findDistinctValuesCount\\(\\) return type has no value type specified in iterable type array\\.$#"
5765-
count: 1
5766-
path: libraries/classes/Normalization.php
5767-
57685763
-
57695764
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:getAllCombinationPartialKeys\\(\\) has parameter \\$primaryKey with no value type specified in iterable type array\\.$#"
57705765
count: 1
57715766
path: libraries/classes/Normalization.php
57725767

5773-
-
5774-
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:getAllCombinationPartialKeys\\(\\) return type has no value type specified in iterable type array\\.$#"
5775-
count: 1
5776-
path: libraries/classes/Normalization.php
5777-
57785768
-
57795769
message: "#^Method PhpMyAdmin\\\\Normalization\\:\\:getHtmlFor3NFstep1\\(\\) has parameter \\$tables with no value type specified in iterable type array\\.$#"
57805770
count: 1

psalm-baseline.xml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8977,12 +8977,9 @@
89778977
<code>$dependents</code>
89788978
<code>$dependents</code>
89798979
<code>$dependents</code>
8980-
<code>$distinctValCount[$column]</code>
8981-
<code>$distinctValCount[$partialKey]</code>
89828980
<code><![CDATA[$dropCols['nonpk']]]></code>
89838981
<code><![CDATA[$dropCols['pk']]]></code>
89848982
<code>$key</code>
8985-
<code>$partialKey</code>
89868983
<code>$table</code>
89878984
<code>$table</code>
89888985
<code>$table</code>
@@ -9012,37 +9009,25 @@
90129009
<code><![CDATA[$dropCols['pk']]]></code>
90139010
<code><![CDATA[$res[0][$column . '_cnt']]]></code>
90149011
</MixedArrayAccess>
9015-
<MixedArrayOffset>
9016-
<code>$dependencyList[$partialKey]</code>
9017-
<code>$distinctValCount[$partialKey]</code>
9018-
<code>$result[$column]</code>
9019-
</MixedArrayOffset>
90209012
<MixedAssignment>
90219013
<code>$arrDependson</code>
90229014
<code>$col</code>
90239015
<code>$cols</code>
9024-
<code>$column</code>
9025-
<code>$column</code>
90269016
<code>$dependent</code>
90279017
<code>$dependents</code>
90289018
<code>$dependents</code>
90299019
<code>$dependents</code>
90309020
<code>$dropCols</code>
90319021
<code>$element</code>
90329022
<code>$key</code>
9033-
<code>$partialKey</code>
90349023
<code>$pkColCnt</code>
9035-
<code>$result[$column]</code>
90369024
<code>$table</code>
90379025
<code>$table</code>
90389026
<code>$tablesList</code>
90399027
<code>$totalRows</code>
90409028
<code>$type</code>
90419029
</MixedAssignment>
90429030
<MixedOperand>
9043-
<code>$column</code>
9044-
<code>$column</code>
9045-
<code>$column</code>
90469031
<code>$element</code>
90479032
</MixedOperand>
90489033
<PossiblyNullArgument>
@@ -9053,6 +9038,9 @@
90539038
<code><![CDATA[$def['Type']]]></code>
90549039
<code><![CDATA[$def['Type']]]></code>
90559040
</PossiblyUndefinedArrayOffset>
9041+
<RedundantCast>
9042+
<code>(string) $dependon</code>
9043+
</RedundantCast>
90569044
</file>
90579045
<file src="libraries/classes/Operations.php">
90589046
<DeprecatedMethod>

0 commit comments

Comments
 (0)