Skip to content

Commit b33e825

Browse files
Merge pull request #18963 from kamil-tekiela/NodeDatabase-natsort
Optimize navigation
2 parents 1c4abc8 + bd4577a commit b33e825

11 files changed

Lines changed: 636 additions & 548 deletions

File tree

phpstan-baseline.neon

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9475,38 +9475,18 @@ parameters:
94759475
count: 1
94769476
path: src/Navigation/NavigationTree.php
94779477

9478-
-
9479-
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeEvent constructor expects string, mixed given\\.$#"
9480-
count: 1
9481-
path: src/Navigation/NavigationTree.php
9482-
9483-
-
9484-
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeFunction constructor expects string, mixed given\\.$#"
9485-
count: 1
9486-
path: src/Navigation/NavigationTree.php
9487-
94889478
-
94899479
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeIndex constructor expects string, mixed given\\.$#"
94909480
count: 1
94919481
path: src/Navigation/NavigationTree.php
94929482

9493-
-
9494-
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeProcedure constructor expects string, mixed given\\.$#"
9495-
count: 1
9496-
path: src/Navigation/NavigationTree.php
9497-
94989483
-
94999484
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeTable constructor expects string, mixed given\\.$#"
9500-
count: 2
9501-
path: src/Navigation/NavigationTree.php
9502-
9503-
-
9504-
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeTrigger constructor expects string, mixed given\\.$#"
95059485
count: 1
95069486
path: src/Navigation/NavigationTree.php
95079487

95089488
-
9509-
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeView constructor expects string, mixed given\\.$#"
9489+
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeTrigger constructor expects string, mixed given\\.$#"
95109490
count: 1
95119491
path: src/Navigation/NavigationTree.php
95129492

@@ -9645,36 +9625,6 @@ parameters:
96459625
count: 1
96469626
path: src/Navigation/Nodes/NodeColumn.php
96479627

9648-
-
9649-
message: "#^Method PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeDatabase\\:\\:getEventCount\\(\\) should return int but returns int\\|string\\.$#"
9650-
count: 1
9651-
path: src/Navigation/Nodes/NodeDatabase.php
9652-
9653-
-
9654-
message: "#^Method PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeDatabase\\:\\:getFunctionCount\\(\\) should return int but returns int\\|string\\.$#"
9655-
count: 1
9656-
path: src/Navigation/Nodes/NodeDatabase.php
9657-
9658-
-
9659-
message: "#^Method PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeDatabase\\:\\:getProcedureCount\\(\\) should return int but returns int\\|string\\.$#"
9660-
count: 1
9661-
path: src/Navigation/Nodes/NodeDatabase.php
9662-
9663-
-
9664-
message: "#^Method PhpMyAdmin\\\\Navigation\\\\Nodes\\\\NodeDatabase\\:\\:getTableOrViewCount\\(\\) should return int but returns int\\|string\\.$#"
9665-
count: 1
9666-
path: src/Navigation/Nodes/NodeDatabase.php
9667-
9668-
-
9669-
message: "#^Parameter \\#2 \\$callback of function usort expects callable\\(mixed, mixed\\)\\: int, 'strnatcasecmp' given\\.$#"
9670-
count: 3
9671-
path: src/Navigation/Nodes/NodeDatabase.php
9672-
9673-
-
9674-
message: "#^Parameter \\#2 \\$callback of function usort expects callable\\(string\\|null, string\\|null\\)\\: int, 'strnatcasecmp' given\\.$#"
9675-
count: 3
9676-
path: src/Navigation/Nodes/NodeDatabase.php
9677-
96789628
-
96799629
message: "#^Cannot access property \\$realName on PhpMyAdmin\\\\Navigation\\\\Nodes\\\\Node\\|false\\.$#"
96809630
count: 1
@@ -9695,6 +9645,21 @@ parameters:
96959645
count: 1
96969646
path: src/Navigation/Nodes/NodeTable.php
96979647

9648+
-
9649+
message: "#^Method PhpMyAdmin\\\\Navigation\\\\Nodes\\\\ObjectFetcher\\:\\:getEventsFromDb\\(\\) should return array\\<string\\> but returns array\\.$#"
9650+
count: 1
9651+
path: src/Navigation/Nodes/ObjectFetcher.php
9652+
9653+
-
9654+
message: "#^Method PhpMyAdmin\\\\Navigation\\\\Nodes\\\\ObjectFetcher\\:\\:getRoutines\\(\\) should return array\\<string\\> but returns array\\.$#"
9655+
count: 1
9656+
path: src/Navigation/Nodes/ObjectFetcher.php
9657+
9658+
-
9659+
message: "#^Method PhpMyAdmin\\\\Navigation\\\\Nodes\\\\ObjectFetcher\\:\\:getTablesAndViews\\(\\) should return array\\<array\\{name\\: string, type\\: string\\}\\> but returns array\\.$#"
9660+
count: 1
9661+
path: src/Navigation/Nodes/ObjectFetcher.php
9662+
96989663
-
96999664
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
97009665
count: 3

psalm-baseline.xml

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5142,7 +5142,7 @@
51425142
</InvalidReturnType>
51435143
<MixedReturnTypeCoercion>
51445144
<code><![CDATA[array<array-key, string|null>]]></code>
5145-
<code><![CDATA[array_column($this->result->fetch_all(), 0)]]></code>
5145+
<code>array_column($result, $column)</code>
51465146
<code><![CDATA[array_column($this->result->fetch_all(), 1, 0)]]></code>
51475147
<code><![CDATA[list<string|null>]]></code>
51485148
</MixedReturnTypeCoercion>
@@ -7002,11 +7002,6 @@
70027002
<code>$item</code>
70037003
<code>$item</code>
70047004
<code>$item</code>
7005-
<code>$item</code>
7006-
<code>$item</code>
7007-
<code>$item</code>
7008-
<code>$item</code>
7009-
<code>$item</code>
70107005
<code>$path</code>
70117006
<code>$path[0]</code>
70127007
<code>$path[0]</code>
@@ -7031,7 +7026,6 @@
70317026
<MixedAssignment>
70327027
<code>$db</code>
70337028
<code>$item</code>
7034-
<code>$item</code>
70357029
<code>$part</code>
70367030
<code>$path</code>
70377031
<code>$path</code>
@@ -7182,43 +7176,9 @@
71827176
<code>Config::getInstance()</code>
71837177
<code>Config::getInstance()</code>
71847178
<code>Config::getInstance()</code>
7185-
<code>Config::getInstance()</code>
7186-
<code>Config::getInstance()</code>
7187-
<code>Config::getInstance()</code>
7188-
<code>Config::getInstance()</code>
7189-
<code>Config::getInstance()</code>
7190-
<code>DatabaseInterface::getInstance()</code>
7191-
<code>DatabaseInterface::getInstance()</code>
7192-
<code>DatabaseInterface::getInstance()</code>
7193-
<code>DatabaseInterface::getInstance()</code>
7194-
<code>DatabaseInterface::getInstance()</code>
7195-
<code>DatabaseInterface::getInstance()</code>
7196-
<code>DatabaseInterface::getInstance()</code>
71977179
<code>DatabaseInterface::getInstance()</code>
71987180
<code>DatabaseInterface::getInstance()</code>
71997181
</DeprecatedMethod>
7200-
<InvalidArgument>
7201-
<code><![CDATA[usort($retval, 'strnatcasecmp')]]></code>
7202-
<code><![CDATA[usort($retval, 'strnatcasecmp')]]></code>
7203-
<code><![CDATA[usort($retval, 'strnatcasecmp')]]></code>
7204-
</InvalidArgument>
7205-
<InvalidReturnStatement>
7206-
<code><![CDATA[$dbi->queryAndGetNumRows($query)]]></code>
7207-
<code><![CDATA[$dbi->queryAndGetNumRows($query)]]></code>
7208-
<code><![CDATA[$dbi->queryAndGetNumRows($query)]]></code>
7209-
<code><![CDATA[$dbi->queryAndGetNumRows($query)]]></code>
7210-
</InvalidReturnStatement>
7211-
<InvalidReturnType>
7212-
<code>int</code>
7213-
<code>int</code>
7214-
<code>int</code>
7215-
<code>int</code>
7216-
</InvalidReturnType>
7217-
<MixedArgumentTypeCoercion>
7218-
<code><![CDATA[usort($retval, 'strnatcasecmp')]]></code>
7219-
<code><![CDATA[usort($retval, 'strnatcasecmp')]]></code>
7220-
<code><![CDATA[usort($retval, 'strnatcasecmp')]]></code>
7221-
</MixedArgumentTypeCoercion>
72227182
</file>
72237183
<file src="src/Navigation/Nodes/NodeDatabaseChild.php">
72247184
<PossiblyInvalidPropertyFetch>
@@ -7255,6 +7215,16 @@
72557215
<code>$secondIcon</code>
72567216
</PossiblyUnusedProperty>
72577217
</file>
7218+
<file src="src/Navigation/Nodes/ObjectFetcher.php">
7219+
<MixedReturnTypeCoercion>
7220+
<code><![CDATA[$this->dbi->fetchResult($query)]]></code>
7221+
<code><![CDATA[$this->dbi->fetchResult($query)]]></code>
7222+
<code><![CDATA[$this->dbi->fetchResult($query)]]></code>
7223+
<code>array{name:string, type:string}[]</code>
7224+
<code>string[]</code>
7225+
<code>string[]</code>
7226+
</MixedReturnTypeCoercion>
7227+
</file>
72587228
<file src="src/Normalization.php">
72597229
<DeprecatedMethod>
72607230
<code>Config::getInstance()</code>
@@ -14366,6 +14336,14 @@
1436614336
<code>[]</code>
1436714337
</InvalidPropertyAssignmentValue>
1436814338
</file>
14339+
<file src="tests/classes/Navigation/Nodes/ObjectFetcherTest.php">
14340+
<DeprecatedMethod>
14341+
<code>Config::getInstance()</code>
14342+
<code>Config::getInstance()</code>
14343+
<code>Config::getInstance()</code>
14344+
<code>Config::getInstance()</code>
14345+
</DeprecatedMethod>
14346+
</file>
1436914347
<file src="tests/classes/NormalizationTest.php">
1437014348
<DeprecatedMethod>
1437114349
<code>Config::getInstance()</code>
@@ -15023,6 +15001,11 @@
1502315001
<InvalidReturnType>
1502415002
<code><![CDATA[array<array-key, string|null>]]></code>
1502515003
</InvalidReturnType>
15004+
<MixedReturnTypeCoercion>
15005+
<code><![CDATA[array_column($this->fetchAllAssoc(), $column)]]></code>
15006+
<code><![CDATA[array_column($this->result, $column)]]></code>
15007+
<code><![CDATA[list<string|null>]]></code>
15008+
</MixedReturnTypeCoercion>
1502615009
<PossiblyUnusedReturnValue>
1502715010
<code>bool</code>
1502815011
</PossiblyUnusedReturnValue>

src/Dbal/MysqliResult.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use function is_string;
2020

2121
use const MYSQLI_ASSOC;
22+
use const MYSQLI_NUM;
2223

2324
/**
2425
* Extension independent database result
@@ -121,12 +122,12 @@ public function fetchAllAssoc(): array
121122
}
122123

123124
/**
124-
* Returns values from the first column of each row
125+
* Returns values from the selected column of each row
125126
*
126127
* @return array<int, string|null>
127128
* @psalm-return list<string|null>
128129
*/
129-
public function fetchAllColumn(): array
130+
public function fetchAllColumn(int|string $column = 0): array
130131
{
131132
if ($this->result === null) {
132133
return [];
@@ -135,7 +136,9 @@ public function fetchAllColumn(): array
135136
// This function should return all rows, not only the remaining rows
136137
$this->result->data_seek(0);
137138

138-
return array_column($this->result->fetch_all(), 0);
139+
$result = is_string($column) ? $this->result->fetch_all(MYSQLI_ASSOC) : $this->result->fetch_all(MYSQLI_NUM);
140+
141+
return array_column($result, $column);
139142
}
140143

141144
/**

src/Dbal/ResultInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public function fetchValue(int|string $field = 0): string|false|null;
5656
public function fetchAllAssoc(): array;
5757

5858
/**
59-
* Returns values from the first column of each row
59+
* Returns values from the selected column of each row
6060
*
6161
* @return array<int, string|null>
6262
* @psalm-return list<string|null>
6363
*/
64-
public function fetchAllColumn(): array;
64+
public function fetchAllColumn(int|string $column = 0): array;
6565

6666
/**
6767
* Returns values as single dimensional array where the key is the first column

0 commit comments

Comments
 (0)