Skip to content

Commit 90db3a1

Browse files
Merge pull request #18621 from kamil-tekiela/fix-doctype-on-arrays
Fix array property declarations
2 parents 609c591 + 104b0c4 commit 90db3a1

File tree

5 files changed

+10
-101
lines changed

5 files changed

+10
-101
lines changed

libraries/classes/Config/Form.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ class Form
3939
/**
4040
* Form fields (paths), filled by {@link readFormPaths()}, indexed by field name
4141
*
42-
* @var mixed[]
42+
* @var string[]
4343
*/
44-
public array $fields;
44+
public array $fields = [];
4545

4646
/**
4747
* Stores default values for some fields (eg. pmadb tables)
4848
*
4949
* @var mixed[]
5050
*/
51-
public array $default;
51+
public array $default = [];
5252

5353
/**
5454
* Caches field types, indexed by field names
5555
*
56-
* @var mixed[]
56+
* @var string[]
5757
*/
58-
private array $fieldsTypes;
58+
private array $fieldsTypes = [];
5959

6060
/**
6161
* A counter for the number of groups
@@ -214,6 +214,7 @@ function ($value, $key, $prefix): void {
214214

215215
// $this->fields is an array of the form: [0..n] => 'field path'
216216
// change numeric indexes to contain field names (last part of the path)
217+
/** @var string[] $paths */
217218
$paths = $this->fields;
218219
$this->fields = [];
219220
foreach ($paths as $path) {
@@ -244,7 +245,7 @@ protected function readTypes(): void
244245
$type = gettype($this->configFile->getDefault($path));
245246
}
246247

247-
$this->fieldsTypes[$name] = $type;
248+
$this->fieldsTypes[$name] = (string) $type;
248249
}
249250
}
250251

libraries/classes/RecentFavoriteTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class RecentFavoriteTable
3939
*
4040
* @var mixed[]
4141
*/
42-
private array $tables;
42+
private array $tables = [];
4343

4444
/**
4545
* RecentFavoriteTable instances.

phpstan-baseline.neon

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -706,22 +706,7 @@ parameters:
706706
path: libraries/classes/Config/ConfigFile.php
707707

708708
-
709-
message: "#^Class PhpMyAdmin\\\\Config\\\\Form has an uninitialized property \\$default\\. Give it default value or assign it in the constructor\\.$#"
710-
count: 1
711-
path: libraries/classes/Config/Form.php
712-
713-
-
714-
message: "#^Class PhpMyAdmin\\\\Config\\\\Form has an uninitialized property \\$fieldsTypes\\. Give it default value or assign it in the constructor\\.$#"
715-
count: 1
716-
path: libraries/classes/Config/Form.php
717-
718-
-
719-
message: "#^Empty array passed to foreach\\.$#"
720-
count: 1
721-
path: libraries/classes/Config/Form.php
722-
723-
-
724-
message: "#^Method PhpMyAdmin\\\\Config\\\\Form\\:\\:getOptionType\\(\\) should return string\\|null but returns mixed\\.$#"
709+
message: "#^Cannot cast mixed to string\\.$#"
725710
count: 1
726711
path: libraries/classes/Config/Form.php
727712

@@ -730,21 +715,11 @@ parameters:
730715
count: 1
731716
path: libraries/classes/Config/Form.php
732717

733-
-
734-
message: "#^Parameter \\#1 \\$canonicalPath of method PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:getDefault\\(\\) expects string, mixed given\\.$#"
735-
count: 1
736-
path: libraries/classes/Config/Form.php
737-
738718
-
739719
message: "#^Parameter \\#1 \\$keys of function array_combine expects array\\<int\\|string\\>, array\\<int\\<0, max\\>, mixed\\> given\\.$#"
740720
count: 1
741721
path: libraries/classes/Config/Form.php
742722

743-
-
744-
message: "#^Parameter \\#1 \\$path of method PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:getDbEntry\\(\\) expects string, mixed given\\.$#"
745-
count: 1
746-
path: libraries/classes/Config/Form.php
747-
748723
-
749724
message: "#^Unreachable statement \\- code above always terminates\\.$#"
750725
count: 2
@@ -845,11 +820,6 @@ parameters:
845820
count: 1
846821
path: libraries/classes/Config/FormDisplay.php
847822

848-
-
849-
message: "#^Parameter \\#1 \\$optionPath of method PhpMyAdmin\\\\Config\\\\Form\\:\\:getOptionValueList\\(\\) expects string, mixed given\\.$#"
850-
count: 2
851-
path: libraries/classes/Config/FormDisplay.php
852-
853823
-
854824
message: "#^Parameter \\#1 \\$path of method PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:getValue\\(\\) expects string, int\\|string\\|false given\\.$#"
855825
count: 1
@@ -867,7 +837,7 @@ parameters:
867837

868838
-
869839
message: "#^Parameter \\#1 \\$path of static method PhpMyAdmin\\\\Config\\\\Descriptions\\:\\:get\\(\\) expects string, mixed given\\.$#"
870-
count: 2
840+
count: 1
871841
path: libraries/classes/Config/FormDisplay.php
872842

873843
-
@@ -915,26 +885,11 @@ parameters:
915885
count: 1
916886
path: libraries/classes/Config/FormDisplay.php
917887

918-
-
919-
message: "#^Parameter \\#3 \\$canonicalPath of method PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:set\\(\\) expects string\\|null, mixed given\\.$#"
920-
count: 1
921-
path: libraries/classes/Config/FormDisplay.php
922-
923888
-
924889
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, int\\|string\\|false given\\.$#"
925890
count: 1
926891
path: libraries/classes/Config/FormDisplay.php
927892

928-
-
929-
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, mixed given\\.$#"
930-
count: 2
931-
path: libraries/classes/Config/FormDisplay.php
932-
933-
-
934-
message: "#^Parameter \\#3 \\$systemPath of method PhpMyAdmin\\\\Config\\\\FormDisplay\\:\\:displayFieldInput\\(\\) expects string, mixed given\\.$#"
935-
count: 1
936-
path: libraries/classes/Config/FormDisplay.php
937-
938893
-
939894
message: "#^Parameter \\#4 \\$workPath of method PhpMyAdmin\\\\Config\\\\FormDisplay\\:\\:displayFieldInput\\(\\) expects string, int\\|string\\|false given\\.$#"
940895
count: 1

psalm-baseline.xml

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -370,39 +370,22 @@
370370
<code>$value</code>
371371
<code>$value</code>
372372
</MissingClosureParamType>
373-
<MixedArgument>
374-
<code>$path</code>
375-
<code>$path</code>
376-
<code>$path</code>
377-
</MixedArgument>
378373
<MixedArgumentTypeCoercion>
379374
<code>$keys</code>
380375
</MixedArgumentTypeCoercion>
381376
<MixedAssignment>
382377
<code>$keys[]</code>
383-
<code>$path</code>
384-
<code>$path</code>
385378
<code>$type</code>
386379
<code>$v</code>
387380
<code>$value</code>
388381
</MixedAssignment>
389-
<MixedInferredReturnType>
390-
<code>string|null</code>
391-
</MixedInferredReturnType>
392382
<MixedOperand>
393383
<code>$key</code>
394384
<code>$prefix</code>
395385
<code>$prefix</code>
396386
<code>$prefix</code>
397387
</MixedOperand>
398-
<MixedReturnStatement>
399-
<code><![CDATA[$this->fieldsTypes[$key] ?? null]]></code>
400-
<code><![CDATA[$this->fieldsTypes[$key] ?? null]]></code>
401-
</MixedReturnStatement>
402388
<PropertyNotSetInConstructor>
403-
<code>$default</code>
404-
<code>$fields</code>
405-
<code>$fieldsTypes</code>
406389
<code>$name</code>
407390
</PropertyNotSetInConstructor>
408391
<UnevaluatedCode>
@@ -414,21 +397,14 @@
414397
<MixedArgument>
415398
<code>$canonicalPath</code>
416399
<code>$errorList</code>
417-
<code><![CDATA[$form->fields[$field]]]></code>
418400
<code>$ip</code>
419401
<code>$key</code>
420-
<code>$path</code>
421-
<code>$path</code>
422-
<code>$path</code>
423-
<code>$systemPath</code>
424-
<code>$systemPath</code>
425402
<code><![CDATA[$this->systemPaths[$systemPath]]]></code>
426403
<code>$translatedPath</code>
427404
<code>$userPrefsDisallow ?? []</code>
428405
<code>$val</code>
429406
<code>$validators[$path]</code>
430407
<code>$value</code>
431-
<code>$workPath</code>
432408
</MixedArgument>
433409
<MixedArgumentTypeCoercion>
434410
<code>$field</code>
@@ -451,20 +427,7 @@
451427
<code>$_POST[$key]</code>
452428
<code>$_POST[$key]</code>
453429
<code>$_POST[$key]</code>
454-
<code><![CDATA[$this->systemPaths[$workPath]]]></code>
455-
<code><![CDATA[$this->translatedPaths[$workPath]]]></code>
456-
<code><![CDATA[$this->userprefsDisallow[$path]]]></code>
457-
<code><![CDATA[$this->userprefsDisallow[$systemPath]]]></code>
458-
<code><![CDATA[$this->userprefsDisallow[$systemPath]]]></code>
459-
<code><![CDATA[$this->userprefsKeys[$path]]]></code>
460-
<code><![CDATA[$this->userprefsKeys[$systemPath]]]></code>
461-
<code>$values[$path]</code>
462-
<code>$values[$path]</code>
463-
<code>$values[$systemPath]</code>
464430
</MixedArrayOffset>
465-
<MixedArrayTypeCoercion>
466-
<code>$values[$path]</code>
467-
</MixedArrayTypeCoercion>
468431
<MixedAssignment>
469432
<code>$canonicalPath</code>
470433
<code>$errorList</code>
@@ -473,14 +436,7 @@
473436
<code>$isSetupScript</code>
474437
<code>$key</code>
475438
<code><![CDATA[$opts['errors']]]></code>
476-
<code>$path</code>
477-
<code>$path</code>
478-
<code>$path</code>
479-
<code>$path</code>
480-
<code>$paths[]</code>
481439
<code><![CDATA[$proxies['-' . $i]]]></code>
482-
<code>$systemPath</code>
483-
<code>$toSave[$workPath]</code>
484440
<code>$translatedPath</code>
485441
<code>$userPrefsDisallow</code>
486442
<code>$v</code>
@@ -492,7 +448,6 @@
492448
<code>$valueDefault</code>
493449
<code>$valueDefaultJs</code>
494450
<code>$values[$path]</code>
495-
<code>$workPath</code>
496451
</MixedAssignment>
497452
<MixedOperand>
498453
<code>$ip</code>

test/classes/Config/FormTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ public function testReadFormPathsCallBack(): void
124124

125125
$this->assertEquals('preffoo/foo/bar/test', $result[0]);
126126

127-
$this->assertIsString($result[1]);
128-
129127
// needs regexp because the counter is static
130128
$this->assertMatchesRegularExpression('/^preffoo\/foo\/bar\/\:group\:end\:\d+$/', $result[1]);
131129
}

0 commit comments

Comments
 (0)