Skip to content

Commit d104e8b

Browse files
committed
Fixed some issues reported by PHPStan
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent c36cced commit d104e8b

File tree

3 files changed

+44
-92
lines changed

3 files changed

+44
-92
lines changed

libraries/classes/InsertEdit.php

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function __construct(
9191
* @param array $whereClauseArray array of where clauses
9292
* @param string $errorUrl error url
9393
*
94-
* @return array array of insert/edit form parameters
94+
* @return array<string, string> array of insert/edit form parameters
9595
*/
9696
public function getFormParametersForInsertForm(
9797
$db,
@@ -123,9 +123,9 @@ public function getFormParametersForInsertForm(
123123
/**
124124
* Creates array of where clauses
125125
*
126-
* @param array|string|null $whereClause where clause
126+
* @param string[]|string|null $whereClause where clause
127127
*
128-
* @return array whereClauseArray array of where clauses
128+
* @return string[] whereClauseArray array of where clauses
129129
*/
130130
private function getWhereClauseArray($whereClause): array
131131
{
@@ -137,17 +137,18 @@ private function getWhereClauseArray($whereClause): array
137137
return $whereClause;
138138
}
139139

140-
return [0 => $whereClause];
140+
return [$whereClause];
141141
}
142142

143143
/**
144144
* Analysing where clauses array
145145
*
146-
* @param array $whereClauseArray array of where clauses
147-
* @param string $table name of the table
148-
* @param string $db name of the database
146+
* @param string[] $whereClauseArray array of where clauses
147+
* @param string $table name of the table
148+
* @param string $db name of the database
149149
*
150-
* @return array $where_clauses, $result, $rows, $found_unique_key
150+
* @return array<int, string[]|ResultInterface[]|array<string, string|null>[]|bool>
151+
* @phpstan-return array{string[], ResultInterface[], array<string, string|null>[], bool}
151152
*/
152153
private function analyzeWhereClauses(
153154
array $whereClauseArray,
@@ -240,9 +241,10 @@ private function showEmptyResultMessageOrSetUniqueCondition(
240241
* @param string $table name of the table
241242
* @param string $db name of the database
242243
*
243-
* @return array containing $result and $rows arrays
244+
* @return array<int, ResultInterface|false[]>
245+
* @phpstan-return array{ResultInterface, false[]}
244246
*/
245-
private function loadFirstRow($table, $db)
247+
private function loadFirstRow($table, $db): array
246248
{
247249
$result = $this->dbi->query(
248250
'SELECT * FROM ' . Util::backquote($db)
@@ -1862,11 +1864,21 @@ public function getTableColumns($db, $table)
18621864
/**
18631865
* Function to determine Insert/Edit rows
18641866
*
1865-
* @param string|null $whereClause where clause
1866-
* @param string $db current database
1867-
* @param string $table current table
1868-
*
1869-
* @return array
1867+
* @param string[]|string|null $whereClause where clause
1868+
* @param string $db current database
1869+
* @param string $table current table
1870+
*
1871+
* @return array<int, bool|string[]|string|ResultInterface|ResultInterface[]|null>
1872+
* @phpstan-return array{
1873+
* bool,
1874+
* string[]|string|null,
1875+
* string[],
1876+
* string[]|null,
1877+
* ResultInterface[]|ResultInterface,
1878+
* array<string, string|null>[]|false[],
1879+
* bool,
1880+
* string|null
1881+
* }
18701882
*/
18711883
public function determineInsertOrEdit($whereClause, $db, $table): array
18721884
{

phpstan-baseline.neon

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4275,16 +4275,6 @@ parameters:
42754275
count: 1
42764276
path: libraries/classes/InsertEdit.php
42774277

4278-
-
4279-
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:analyzeWhereClauses\\(\\) has parameter \\$whereClauseArray with no value type specified in iterable type array\\.$#"
4280-
count: 1
4281-
path: libraries/classes/InsertEdit.php
4282-
4283-
-
4284-
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:analyzeWhereClauses\\(\\) return type has no value type specified in iterable type array\\.$#"
4285-
count: 1
4286-
path: libraries/classes/InsertEdit.php
4287-
42884278
-
42894279
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:buildSqlQuery\\(\\) has parameter \\$queryFields with no value type specified in iterable type array\\.$#"
42904280
count: 1
@@ -4295,11 +4285,6 @@ parameters:
42954285
count: 1
42964286
path: libraries/classes/InsertEdit.php
42974287

4298-
-
4299-
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:determineInsertOrEdit\\(\\) return type has no value type specified in iterable type array\\.$#"
4300-
count: 1
4301-
path: libraries/classes/InsertEdit.php
4302-
43034288
-
43044289
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:executeSqlQuery\\(\\) has parameter \\$query with no value type specified in iterable type array\\.$#"
43054290
count: 1
@@ -4435,11 +4420,6 @@ parameters:
44354420
count: 1
44364421
path: libraries/classes/InsertEdit.php
44374422

4438-
-
4439-
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:getFormParametersForInsertForm\\(\\) return type has no value type specified in iterable type array\\.$#"
4440-
count: 1
4441-
path: libraries/classes/InsertEdit.php
4442-
44434423
-
44444424
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:getHeadAndFootOfInsertRowTable\\(\\) has parameter \\$urlParams with no value type specified in iterable type array\\.$#"
44454425
count: 1
@@ -4635,16 +4615,6 @@ parameters:
46354615
count: 1
46364616
path: libraries/classes/InsertEdit.php
46374617

4638-
-
4639-
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:getWhereClauseArray\\(\\) has parameter \\$whereClause with no value type specified in iterable type array\\.$#"
4640-
count: 1
4641-
path: libraries/classes/InsertEdit.php
4642-
4643-
-
4644-
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:getWhereClauseArray\\(\\) return type has no value type specified in iterable type array\\.$#"
4645-
count: 1
4646-
path: libraries/classes/InsertEdit.php
4647-
46484618
-
46494619
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:isColumn\\(\\) has parameter \\$column with no value type specified in iterable type array\\.$#"
46504620
count: 1
@@ -4655,11 +4625,6 @@ parameters:
46554625
count: 1
46564626
path: libraries/classes/InsertEdit.php
46574627

4658-
-
4659-
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:loadFirstRow\\(\\) return type has no value type specified in iterable type array\\.$#"
4660-
count: 1
4661-
path: libraries/classes/InsertEdit.php
4662-
46634628
-
46644629
message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:showEmptyResultMessageOrSetUniqueCondition\\(\\) has parameter \\$rows with no value type specified in iterable type array\\.$#"
46654630
count: 1

psalm-baseline.xml

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,52 +3156,35 @@
31563156
</MixedAssignment>
31573157
</file>
31583158
<file src="libraries/classes/Controllers/Table/ChangeController.php">
3159-
<MixedArgument occurrences="20">
3160-
<code>$GLOBALS['current_result']</code>
3159+
<MixedArgument occurrences="7">
31613160
<code>$GLOBALS['disp_message']</code>
3162-
<code>$GLOBALS['insert_mode']</code>
3163-
<code>$GLOBALS['jsvkey']</code>
31643161
<code>$GLOBALS['repopulate']</code>
3165-
<code>$GLOBALS['rows']</code>
31663162
<code>$GLOBALS['unsaved_values']</code>
31673163
<code>$GLOBALS['unsaved_values']</code>
3168-
<code>$GLOBALS['where_clause']</code>
31693164
<code>$GLOBALS['where_clause'] ?? null</code>
3170-
<code>$GLOBALS['where_clause_array']</code>
3171-
<code>$GLOBALS['where_clause_array']</code>
3172-
<code>$GLOBALS['where_clause_array']</code>
3173-
<code>$GLOBALS['where_clause_array']</code>
3174-
<code>$GLOBALS['where_clauses']</code>
3175-
<code>$current_row</code>
31763165
<code>$isUpload</code>
31773166
<code>$isUpload</code>
3178-
<code>$row_id</code>
3179-
<code>$row_id</code>
31803167
</MixedArgument>
3181-
<MixedArgumentTypeCoercion occurrences="1">
3168+
<MixedArgumentTypeCoercion occurrences="4">
3169+
<code>$GLOBALS['jsvkey']</code>
31823170
<code>$GLOBALS['urlParams']</code>
3171+
<code>$row_id</code>
3172+
<code>$row_id</code>
31833173
</MixedArgumentTypeCoercion>
3184-
<MixedArrayOffset occurrences="3">
3185-
<code>$GLOBALS['result'][$row_id]</code>
3186-
<code>$GLOBALS['result'][$row_id]</code>
3187-
<code>$GLOBALS['unsaved_values'][$row_id]</code>
3188-
</MixedArrayOffset>
3189-
<MixedAssignment occurrences="32">
3174+
<MixedAssignment occurrences="28">
31903175
<code>$GLOBALS['after_insert']</code>
31913176
<code>$GLOBALS['biggest_max_file_size']</code>
31923177
<code>$GLOBALS['checked']</code>
31933178
<code>$GLOBALS['chg_evt_handler']</code>
31943179
<code>$GLOBALS['columns_cnt']</code>
31953180
<code>$GLOBALS['comments_map']</code>
31963181
<code>$GLOBALS['current_result']</code>
3197-
<code>$GLOBALS['current_result']</code>
31983182
<code>$GLOBALS['disp_message']</code>
31993183
<code>$GLOBALS['errorUrl']</code>
32003184
<code>$GLOBALS['found_unique_key']</code>
32013185
<code>$GLOBALS['has_blob_field']</code>
32023186
<code>$GLOBALS['insert_mode']</code>
32033187
<code>$GLOBALS['jsvkey']</code>
3204-
<code>$GLOBALS['jsvkey']</code>
32053188
<code>$GLOBALS['o_rows']</code>
32063189
<code>$GLOBALS['repopulate']</code>
32073190
<code>$GLOBALS['repopulate']</code>
@@ -3216,29 +3199,18 @@
32163199
<code>$GLOBALS['where_clause']</code>
32173200
<code>$GLOBALS['where_clause_array']</code>
32183201
<code>$GLOBALS['where_clauses']</code>
3219-
<code>$current_row</code>
32203202
<code>$isUpload</code>
3221-
<code>$row_id</code>
32223203
</MixedAssignment>
3223-
<MixedOperand occurrences="2">
3204+
<MixedOperand occurrences="1">
32243205
<code>$GLOBALS['biggest_max_file_size']</code>
3225-
<code>$GLOBALS['jsvkey']</code>
32263206
</MixedOperand>
32273207
<PossiblyInvalidArgument occurrences="1">
32283208
<code>$GLOBALS['current_result']</code>
32293209
</PossiblyInvalidArgument>
3230-
<PossiblyNullArgument occurrences="7">
3231-
<code>$GLOBALS['insert_mode']</code>
3210+
<PossiblyNullArgument occurrences="2">
32323211
<code>$GLOBALS['text_dir']</code>
3233-
<code>$GLOBALS['where_clause_array']</code>
3234-
<code>$GLOBALS['where_clause_array']</code>
3235-
<code>$GLOBALS['where_clause_array']</code>
3236-
<code>$GLOBALS['where_clause_array']</code>
32373212
<code>$isUpload</code>
32383213
</PossiblyNullArgument>
3239-
<PossiblyNullIterator occurrences="1">
3240-
<code>$GLOBALS['rows']</code>
3241-
</PossiblyNullIterator>
32423214
<TypeDoesNotContainType occurrences="1">
32433215
<code>$GLOBALS['biggest_max_file_size'] &gt; 0</code>
32443216
</TypeDoesNotContainType>
@@ -7936,7 +7908,8 @@
79367908
</MixedAssignment>
79377909
</file>
79387910
<file src="libraries/classes/InsertEdit.php">
7939-
<MixedArgument occurrences="80">
7911+
<LessSpecificReturnStatement occurrences="1"/>
7912+
<MixedArgument occurrences="79">
79407913
<code>$_POST['fields']['multi_edit']</code>
79417914
<code>$_POST['fields']['multi_edit'][$rownumber][$key]</code>
79427915
<code>$backupField</code>
@@ -8015,7 +7988,6 @@
80157988
<code>$whereClause</code>
80167989
<code>$whereClause</code>
80177990
<code>$whereClause</code>
8018-
<code>$whereClause</code>
80197991
<code>min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars'])</code>
80207992
</MixedArgument>
80217993
<MixedArgumentTypeCoercion occurrences="8">
@@ -8072,7 +8044,7 @@
80728044
<code>$mimeMap[$tableColumn['Field']]</code>
80738045
<code>$protectedRow[$multiEditColumnsName[$key]]</code>
80748046
</MixedArrayOffset>
8075-
<MixedAssignment occurrences="37">
8047+
<MixedAssignment occurrences="36">
80768048
<code>$GLOBALS['cfg']['ShowFieldTypesInDataEditView']</code>
80778049
<code>$GLOBALS['cfg']['ShowFunctionFields']</code>
80788050
<code>$_SESSION['edit_next']</code>
@@ -8109,7 +8081,6 @@
81098081
<code>$whereClause</code>
81108082
<code>$whereClause</code>
81118083
<code>$whereClause</code>
8112-
<code>$whereClause</code>
81138084
</MixedAssignment>
81148085
<MixedInferredReturnType occurrences="2">
81158086
<code>int</code>
@@ -8119,7 +8090,7 @@
81198090
<code>new $className()</code>
81208091
<code>new $className()</code>
81218092
</MixedMethodCall>
8122-
<MixedOperand occurrences="9">
8093+
<MixedOperand occurrences="8">
81238094
<code>$_POST['where_clause'][0]</code>
81248095
<code>$column['pma_type']</code>
81258096
<code>$file</code>
@@ -8128,11 +8099,15 @@
81288099
<code>$multiEditFuncs[$key]</code>
81298100
<code>$multiEditFuncs[$key]</code>
81308101
<code>$multiEditFuncs[$key]</code>
8131-
<code>$whereClause</code>
81328102
</MixedOperand>
81338103
<MixedReturnStatement occurrences="2">
81348104
<code>$_POST['err_url']</code>
81358105
</MixedReturnStatement>
8106+
<MixedReturnTypeCoercion occurrences="2">
8107+
<code>$formParams</code>
8108+
<code>array&lt;string, string&gt;</code>
8109+
</MixedReturnTypeCoercion>
8110+
<MoreSpecificReturnType occurrences="1"/>
81368111
<PossiblyNullArgument occurrences="2">
81378112
<code>$newValue</code>
81388113
<code>$newValue</code>

0 commit comments

Comments
 (0)