Skip to content

Commit bde143d

Browse files
Merge pull request #19484 from kamil-tekiela/Remove-unnecessary-nullability
Remove unnecessary nullability
2 parents 358e9a1 + 4e9866f commit bde143d

File tree

15 files changed

+147
-191
lines changed

15 files changed

+147
-191
lines changed

phpstan-baseline.neon

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,37 +3898,37 @@ parameters:
38983898
path: src/Controllers/Sql/SqlController.php
38993899

39003900
-
3901-
message: '#^Parameter \#10 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string\|null, mixed given\.$#'
3901+
message: '#^Parameter \#11 \$completeQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string, mixed given\.$#'
39023902
identifier: argument.type
39033903
count: 1
39043904
path: src/Controllers/Sql/SqlController.php
39053905

39063906
-
3907-
message: '#^Parameter \#12 \$completeQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#'
3907+
message: '#^Parameter \#2 \$signature of static method PhpMyAdmin\\Core\:\:checkSqlQuerySignature\(\) expects string, mixed given\.$#'
39083908
identifier: argument.type
39093909
count: 1
39103910
path: src/Controllers/Sql/SqlController.php
39113911

39123912
-
3913-
message: '#^Parameter \#2 \$signature of static method PhpMyAdmin\\Core\:\:checkSqlQuerySignature\(\) expects string, mixed given\.$#'
3913+
message: '#^Parameter \#5 \$sqlQueryForBookmark of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string, mixed given\.$#'
39143914
identifier: argument.type
39153915
count: 1
39163916
path: src/Controllers/Sql/SqlController.php
39173917

39183918
-
3919-
message: '#^Parameter \#5 \$sqlQueryForBookmark of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#'
3919+
message: '#^Parameter \#6 \$messageToShow of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string, mixed given\.$#'
39203920
identifier: argument.type
39213921
count: 1
39223922
path: src/Controllers/Sql/SqlController.php
39233923

39243924
-
3925-
message: '#^Parameter \#6 \$messageToShow of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#'
3925+
message: '#^Parameter \#8 \$dispQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#'
39263926
identifier: argument.type
39273927
count: 1
39283928
path: src/Controllers/Sql/SqlController.php
39293929

39303930
-
3931-
message: '#^Parameter \#9 \$dispQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#'
3931+
message: '#^Parameter \#9 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string, mixed given\.$#'
39323932
identifier: argument.type
39333933
count: 1
39343934
path: src/Controllers/Sql/SqlController.php
@@ -4186,25 +4186,25 @@ parameters:
41864186
path: src/Controllers/Table/DeleteRowsController.php
41874187

41884188
-
4189-
message: '#^Parameter \#10 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string\|null, mixed given\.$#'
4189+
message: '#^Parameter \#3 \$pos of method PhpMyAdmin\\Sql\:\:calculatePosForLastPage\(\) expects int\|null, mixed given\.$#'
41904190
identifier: argument.type
41914191
count: 1
41924192
path: src/Controllers/Table/DeleteRowsController.php
41934193

41944194
-
4195-
message: '#^Parameter \#3 \$pos of method PhpMyAdmin\\Sql\:\:calculatePosForLastPage\(\) expects int\|null, mixed given\.$#'
4195+
message: '#^Parameter \#3 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#'
41964196
identifier: argument.type
41974197
count: 1
41984198
path: src/Controllers/Table/DeleteRowsController.php
41994199

42004200
-
4201-
message: '#^Parameter \#3 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#'
4201+
message: '#^Parameter \#8 \$dispQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#'
42024202
identifier: argument.type
42034203
count: 1
42044204
path: src/Controllers/Table/DeleteRowsController.php
42054205

42064206
-
4207-
message: '#^Parameter \#9 \$dispQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#'
4207+
message: '#^Parameter \#9 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string, mixed given\.$#'
42084208
identifier: argument.type
42094209
count: 1
42104210
path: src/Controllers/Table/DeleteRowsController.php
@@ -15915,19 +15915,13 @@ parameters:
1591515915
-
1591615916
message: '#^Only booleans are allowed in &&, string given on the right side\.$#'
1591715917
identifier: booleanAnd.rightNotBoolean
15918-
count: 2
15919-
path: src/Sql.php
15920-
15921-
-
15922-
message: '#^Only booleans are allowed in &&, string\|null given on the left side\.$#'
15923-
identifier: booleanAnd.leftNotBoolean
15924-
count: 1
15918+
count: 3
1592515919
path: src/Sql.php
1592615920

1592715921
-
1592815922
message: '#^Only booleans are allowed in &&, string\|null given on the right side\.$#'
1592915923
identifier: booleanAnd.rightNotBoolean
15930-
count: 2
15924+
count: 1
1593115925
path: src/Sql.php
1593215926

1593315927
-
@@ -15991,13 +15985,7 @@ parameters:
1599115985
path: src/Sql.php
1599215986

1599315987
-
15994-
message: '#^Parameter \#2 \$table of method PhpMyAdmin\\Sql\:\:handleSortOrder\(\) expects string, string\|null given\.$#'
15995-
identifier: argument.type
15996-
count: 1
15997-
path: src/Sql.php
15998-
15999-
-
16000-
message: '#^Parameter \#3 \$column of method PhpMyAdmin\\Sql\:\:cleanupRelations\(\) expects string\|null, mixed given\.$#'
15988+
message: '#^Parameter \#3 \$column of method PhpMyAdmin\\Sql\:\:cleanupRelations\(\) expects string, mixed given\.$#'
1600115989
identifier: argument.type
1600215990
count: 1
1600315991
path: src/Sql.php
@@ -16009,7 +15997,7 @@ parameters:
1600915997
path: src/Sql.php
1601015998

1601115999
-
16012-
message: '#^Parameter \#5 \$bookmarkLabel of method PhpMyAdmin\\Sql\:\:storeTheQueryAsBookmark\(\) expects string, mixed given\.$#'
16000+
message: '#^Parameter \#4 \$bookmarkLabel of method PhpMyAdmin\\Sql\:\:storeTheQueryAsBookmark\(\) expects string, mixed given\.$#'
1601316001
identifier: argument.type
1601416002
count: 1
1601516003
path: src/Sql.php

psalm-baseline.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,8 +2373,8 @@
23732373
<code><![CDATA[$GLOBALS['unlim_num_rows']]]></code>
23742374
</InvalidArrayOffset>
23752375
<MixedArgument>
2376-
<code><![CDATA[$GLOBALS['disp_message'] ?? null]]></code>
2377-
<code><![CDATA[$GLOBALS['message_to_show'] ?? null]]></code>
2376+
<code><![CDATA[$GLOBALS['disp_message'] ?? '']]></code>
2377+
<code><![CDATA[$GLOBALS['message_to_show'] ?? '']]></code>
23782378
<code><![CDATA[$request->getQueryParam('sql_signature')]]></code>
23792379
</MixedArgument>
23802380
<MixedArrayAccess>
@@ -2568,7 +2568,7 @@
25682568
<code><![CDATA[$GLOBALS['disp_query']]]></code>
25692569
</InvalidArrayOffset>
25702570
<MixedArgument>
2571-
<code><![CDATA[$GLOBALS['disp_message'] ?? null]]></code>
2571+
<code><![CDATA[$GLOBALS['disp_message'] ?? '']]></code>
25722572
<code><![CDATA[$GLOBALS['disp_query'] ?? null]]></code>
25732573
<code><![CDATA[$row]]></code>
25742574
</MixedArgument>
@@ -9341,14 +9341,15 @@
93419341
</NullableReturnStatement>
93429342
<PossiblyInvalidArgument>
93439343
<code><![CDATA[$_POST['bkm_label']]]></code>
9344-
<code><![CDATA[$_POST['dropped_column'] ?? null]]></code>
9344+
<code><![CDATA[$_POST['dropped_column'] ?? '']]></code>
93459345
<code><![CDATA[$numRows]]></code>
93469346
<code><![CDATA[$numRows]]></code>
93479347
<code><![CDATA[$numRows]]></code>
93489348
<code><![CDATA[$numRows]]></code>
93499349
</PossiblyInvalidArgument>
93509350
<PossiblyInvalidCast>
93519351
<code><![CDATA[$_POST['bkm_label']]]></code>
9352+
<code><![CDATA[$_POST['dropped_column'] ?? '']]></code>
93529353
</PossiblyInvalidCast>
93539354
<PossiblyInvalidOperand>
93549355
<code><![CDATA[$numRows]]></code>
@@ -9362,7 +9363,6 @@
93629363
<code><![CDATA[$statementInfo->parser->list]]></code>
93639364
<code><![CDATA[$statementInfo->parser->list]]></code>
93649365
<code><![CDATA[$statementInfo->parser->list]]></code>
9365-
<code><![CDATA[$table]]></code>
93669366
</PossiblyNullArgument>
93679367
<PossiblyNullReference>
93689368
<code><![CDATA[has]]></code>
@@ -9375,8 +9375,6 @@
93759375
</RedundantCondition>
93769376
<RiskyTruthyFalsyComparison>
93779377
<code><![CDATA[! $index->isUnique()]]></code>
9378-
<code><![CDATA[$messageToShow]]></code>
9379-
<code><![CDATA[$sqlQueryForBookmark]]></code>
93809378
<code><![CDATA[$table]]></code>
93819379
<code><![CDATA[empty($_GET['id_bookmark'])]]></code>
93829380
<code><![CDATA[empty($_GET['id_bookmark'])]]></code>

src/Config/Form.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public function __construct(
8484
*
8585
* @param string $optionName path or field name
8686
*
87-
* @return string|null one of: boolean, integer, double, string, select, array
87+
* @return string one of: boolean, integer, double, string, select, array
8888
*/
89-
public function getOptionType(string $optionName): string|null
89+
public function getOptionType(string $optionName): string
9090
{
9191
$key = ltrim(
9292
mb_substr(
@@ -96,7 +96,7 @@ public function getOptionType(string $optionName): string|null
9696
'/',
9797
);
9898

99-
return $this->fieldsTypes[$key] ?? null;
99+
return $this->fieldsTypes[$key] ?? '';
100100
}
101101

102102
/**

src/Config/FormDisplay.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,17 @@ private function validate(): void
204204
/**
205205
* Outputs HTML for forms
206206
*
207-
* @param bool $showButtons whether show submit and reset button
208-
* @param string|null $formAction action attribute for the form
209-
* @param mixed[]|null $hiddenFields array of form hidden fields (key: field
207+
* @param bool $showButtons whether show submit and reset button
208+
* @param string $formAction action attribute for the form
209+
* @param mixed[] $hiddenFields array of form hidden fields (key: field
210210
* name)
211211
*
212212
* @return string HTML for forms
213213
*/
214214
public function getDisplay(
215215
bool $showButtons = true,
216-
string|null $formAction = null,
217-
array|null $hiddenFields = null,
216+
string $formAction = '',
217+
array $hiddenFields = [],
218218
): string {
219219
$fieldValidators = [];
220220
$defaultValues = [];
@@ -293,7 +293,7 @@ public function getDisplay(
293293
return $this->formDisplayTemplate->display([
294294
'action' => $formAction,
295295
'has_check_page_refresh' => self::$hasCheckPageRefresh,
296-
'hidden_fields' => (array) $hiddenFields,
296+
'hidden_fields' => $hiddenFields,
297297
'tabs' => $tabs,
298298
'forms' => $forms,
299299
'show_buttons' => $showButtons,
@@ -566,7 +566,7 @@ public function save(array $forms, bool $allowPartialSave = true): bool
566566
foreach ($form->fields as $field => $systemPath) {
567567
$workPath = array_search($systemPath, $this->systemPaths);
568568
$key = $this->translatedPaths[$workPath];
569-
$type = (string) $form->getOptionType($field);
569+
$type = $form->getOptionType($field);
570570

571571
// skip groups
572572
if ($type === 'group') {

src/ConfigStorage/Relation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,10 +1235,10 @@ public function renameTable(string $sourceDb, string $targetDb, string $sourceTa
12351235
/**
12361236
* Create a PDF page
12371237
*
1238-
* @param string|null $newpage name of the new PDF page
1239-
* @param string $db database name
1238+
* @param string $newpage name of the new PDF page
1239+
* @param string $db database name
12401240
*/
1241-
public function createPage(string|null $newpage, PdfFeature $pdfFeature, string $db): int
1241+
public function createPage(string $newpage, PdfFeature $pdfFeature, string $db): int
12421242
{
12431243
$insQuery = 'INSERT INTO '
12441244
. Util::backquote($pdfFeature->database) . '.'
@@ -1247,7 +1247,7 @@ public function createPage(string|null $newpage, PdfFeature $pdfFeature, string
12471247
. ' VALUES ('
12481248
. $this->dbi->quoteString($db, ConnectionType::ControlUser) . ', '
12491249
. $this->dbi->quoteString(
1250-
$newpage !== null && $newpage !== '' ? $newpage : __('no description'),
1250+
$newpage !== '' ? $newpage : __('no description'),
12511251
ConnectionType::ControlUser,
12521252
) . ')';
12531253
$this->dbi->tryQueryAsControlUser($insQuery);

src/Controllers/Database/CentralColumnsController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __invoke(ServerRequest $request): Response
4242
$request->getParsedBodyParamAsString('orig_col_name'),
4343
$request->getParsedBodyParamAsString('col_default'),
4444
$request->getParsedBodyParamAsString('col_default_sel'),
45-
$request->getParsedBodyParamAsStringOrNull('col_extra'),
45+
$request->getParsedBodyParamAsString('col_extra', ''),
4646
$request->getParsedBodyParamAsStringOrNull('col_isNull'),
4747
$request->getParsedBodyParamAsString('col_length'),
4848
$request->getParsedBodyParamAsString('col_attribute'),
@@ -60,7 +60,7 @@ public function __invoke(ServerRequest $request): Response
6060
$request->getParsedBodyParamAsString('col_name'),
6161
$request->getParsedBodyParamAsString('col_default'),
6262
$request->getParsedBodyParamAsString('col_default_sel'),
63-
$request->getParsedBodyParamAsStringOrNull('col_extra'),
63+
$request->getParsedBodyParamAsString('col_extra', ''),
6464
$request->getParsedBodyParamAsStringOrNull('col_isNull'),
6565
$request->getParsedBodyParamAsString('col_length'),
6666
$request->getParsedBodyParamAsString('col_attribute'),
@@ -176,7 +176,7 @@ public function editSave(
176176
string $origColName,
177177
string $colDefault,
178178
string $colDefaultSel,
179-
string|null $colExtra,
179+
string $colExtra,
180180
string|null $colIsNull,
181181
string $colLength,
182182
string $colAttribute,
@@ -198,7 +198,7 @@ public function editSave(
198198
$colLength,
199199
$colIsNull !== null,
200200
$collation,
201-
$colExtra ?? '',
201+
$colExtra,
202202
$columnDefault,
203203
);
204204
}
@@ -207,7 +207,7 @@ public function addNewColumn(
207207
string $colName,
208208
string $colDefault,
209209
string $colDefaultSel,
210-
string|null $colExtra,
210+
string $colExtra,
211211
string|null $colIsNull,
212212
string $colLength,
213213
string $colAttribute,
@@ -224,7 +224,7 @@ public function addNewColumn(
224224
$colLength,
225225
$colIsNull !== null,
226226
$collation,
227-
$colExtra ?? '',
227+
$colExtra,
228228
$colDefault === 'NONE' && $colDefaultSel !== 'USER_DEFINED' ? '' : $colDefault,
229229
);
230230
}

src/Controllers/Import/ImportController.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -649,25 +649,21 @@ public function __invoke(ServerRequest $request): Response
649649
false, // is_gotofile
650650
Current::$database, // db
651651
Current::$table, // table
652-
null, // sql_query_for_bookmark - see below
653-
null, // message_to_show
654-
null, // sql_data
652+
'', // sql_query_for_bookmark - see below
653+
'', // message_to_show
655654
UrlParams::$goto, // goto
656655
null, // disp_query
657-
null, // disp_message
656+
'', // disp_message
658657
Current::$sqlQuery,
659-
null, // complete_query
658+
Current::$sqlQuery, // complete_query
660659
);
661660
}
662661

663662
// sql_query_for_bookmark is not included in Sql::executeQueryAndGetQueryResponse
664663
// since only one bookmark has to be added for all the queries submitted through
665664
// the SQL tab
666665
if (! empty($request->getParsedBodyParam('bkm_label')) && ! empty($GLOBALS['import_text'])) {
667-
$relation = new Relation($this->dbi);
668-
669666
$this->sql->storeTheQueryAsBookmark(
670-
$relation->getRelationParameters()->bookmarkFeature,
671667
Current::$database,
672668
$config->selectedServer['user'],
673669
$request->getParsedBodyParamAsString('sql_query'),
@@ -695,7 +691,6 @@ public function __invoke(ServerRequest $request): Response
695691
$relation = new Relation($this->dbi);
696692

697693
$this->sql->storeTheQueryAsBookmark(
698-
$relation->getRelationParameters()->bookmarkFeature,
699694
Current::$database,
700695
$config->selectedServer['user'],
701696
$request->getParsedBodyParamAsString('sql_query'),

src/Controllers/Sql/SqlController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,13 @@ public function __invoke(ServerRequest $request): Response
191191
$isGotofile,
192192
Current::$database,
193193
Current::$table,
194-
$GLOBALS['import_text'] ?? null,
195-
$GLOBALS['message_to_show'] ?? null,
196-
null,
194+
$GLOBALS['import_text'] ?? '',
195+
$GLOBALS['message_to_show'] ?? '',
197196
UrlParams::$goto,
198197
isset($GLOBALS['disp_query']) ? $GLOBALS['display_query'] : null,
199-
$GLOBALS['disp_message'] ?? null,
198+
$GLOBALS['disp_message'] ?? '',
200199
Current::$sqlQuery,
201-
$GLOBALS['complete_query'] ?? null,
200+
$GLOBALS['complete_query'] ?? Current::$sqlQuery,
202201
));
203202

204203
return $this->response->response();

src/Controllers/Table/DeleteRowsController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,13 @@ public function __invoke(ServerRequest $request): Response
8787
false,
8888
Current::$database,
8989
Current::$table,
90-
null,
91-
null,
92-
null,
90+
'',
91+
'',
9392
UrlParams::$goto,
9493
$GLOBALS['disp_query'] ?? null,
95-
$GLOBALS['disp_message'] ?? null,
94+
$GLOBALS['disp_message'] ?? '',
95+
Current::$sqlQuery,
9696
Current::$sqlQuery,
97-
null,
9897
));
9998

10099
return $this->response->response();

0 commit comments

Comments
 (0)