Skip to content

Commit da2468f

Browse files
Merge pull request #20032 from kamil-tekiela/Validator-refactoring
Validator refactoring
2 parents 69f50f9 + b42b9f4 commit da2468f

6 files changed

Lines changed: 106 additions & 131 deletions

File tree

phpstan-baseline.neon

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,6 @@ parameters:
636636
count: 2
637637
path: src/Config/FormDisplay.php
638638

639-
-
640-
message: '#^Parameter \#2 \$validators of method PhpMyAdmin\\Config\\FormDisplayTemplate\:\:addJsValidate\(\) expects array\<mixed\>\|string, mixed given\.$#'
641-
identifier: argument.type
642-
count: 1
643-
path: src/Config/FormDisplay.php
644-
645639
-
646640
message: '#^Parameter \#3 \$subject of function str_replace expects array\<string\>\|string, int\|string\|false given\.$#'
647641
identifier: argument.type
@@ -1068,12 +1062,6 @@ parameters:
10681062
count: 1
10691063
path: src/Config/Validator.php
10701064

1071-
-
1072-
message: '#^Method PhpMyAdmin\\Config\\Validator\:\:getValidators\(\) should return array\<mixed\> but returns array\|null\.$#'
1073-
identifier: return.type
1074-
count: 2
1075-
path: src/Config/Validator.php
1076-
10771065
-
10781066
message: '#^Only booleans are allowed in a negated boolean, mysqli\|false given\.$#'
10791067
identifier: booleanNot.exprNotBoolean
@@ -1099,7 +1087,7 @@ parameters:
10991087
path: src/Config/Validator.php
11001088

11011089
-
1102-
message: '#^Parameter \#1 \$host of static method PhpMyAdmin\\Config\\Validator\:\:testDBConnection\(\) expects string, mixed given\.$#'
1090+
message: '#^Parameter \#1 \$host of method PhpMyAdmin\\Config\\Validator\:\:testDBConnection\(\) expects string, mixed given\.$#'
11031091
identifier: argument.type
11041092
count: 2
11051093
path: src/Config/Validator.php
@@ -1111,55 +1099,55 @@ parameters:
11111099
path: src/Config/Validator.php
11121100

11131101
-
1114-
message: '#^Parameter \#1 \$path of static method PhpMyAdmin\\Config\\Validator\:\:validateByRegex\(\) expects string, mixed given\.$#'
1102+
message: '#^Parameter \#1 \$path of method PhpMyAdmin\\Config\\Validator\:\:validateByRegex\(\) expects string, mixed given\.$#'
11151103
identifier: argument.type
11161104
count: 1
11171105
path: src/Config/Validator.php
11181106

11191107
-
1120-
message: '#^Parameter \#1 \$path of static method PhpMyAdmin\\Config\\Validator\:\:validateNonNegativeNumber\(\) expects string, mixed given\.$#'
1108+
message: '#^Parameter \#1 \$path of method PhpMyAdmin\\Config\\Validator\:\:validateNonNegativeNumber\(\) expects string, mixed given\.$#'
11211109
identifier: argument.type
11221110
count: 1
11231111
path: src/Config/Validator.php
11241112

11251113
-
1126-
message: '#^Parameter \#1 \$path of static method PhpMyAdmin\\Config\\Validator\:\:validatePMAStorage\(\) expects string, mixed given\.$#'
1114+
message: '#^Parameter \#1 \$path of method PhpMyAdmin\\Config\\Validator\:\:validatePMAStorage\(\) expects string, mixed given\.$#'
11271115
identifier: argument.type
11281116
count: 1
11291117
path: src/Config/Validator.php
11301118

11311119
-
1132-
message: '#^Parameter \#1 \$path of static method PhpMyAdmin\\Config\\Validator\:\:validatePortNumber\(\) expects string, mixed given\.$#'
1120+
message: '#^Parameter \#1 \$path of method PhpMyAdmin\\Config\\Validator\:\:validatePortNumber\(\) expects string, mixed given\.$#'
11331121
identifier: argument.type
11341122
count: 1
11351123
path: src/Config/Validator.php
11361124

11371125
-
1138-
message: '#^Parameter \#1 \$path of static method PhpMyAdmin\\Config\\Validator\:\:validatePositiveNumber\(\) expects string, mixed given\.$#'
1126+
message: '#^Parameter \#1 \$path of method PhpMyAdmin\\Config\\Validator\:\:validatePositiveNumber\(\) expects string, mixed given\.$#'
11391127
identifier: argument.type
11401128
count: 1
11411129
path: src/Config/Validator.php
11421130

11431131
-
1144-
message: '#^Parameter \#1 \$path of static method PhpMyAdmin\\Config\\Validator\:\:validateRegex\(\) expects string, mixed given\.$#'
1132+
message: '#^Parameter \#1 \$path of method PhpMyAdmin\\Config\\Validator\:\:validateRegex\(\) expects string, mixed given\.$#'
11451133
identifier: argument.type
11461134
count: 1
11471135
path: src/Config/Validator.php
11481136

11491137
-
1150-
message: '#^Parameter \#1 \$path of static method PhpMyAdmin\\Config\\Validator\:\:validateServer\(\) expects string, mixed given\.$#'
1138+
message: '#^Parameter \#1 \$path of method PhpMyAdmin\\Config\\Validator\:\:validateServer\(\) expects string, mixed given\.$#'
11511139
identifier: argument.type
11521140
count: 1
11531141
path: src/Config/Validator.php
11541142

11551143
-
1156-
message: '#^Parameter \#1 \$path of static method PhpMyAdmin\\Config\\Validator\:\:validateTrustedProxies\(\) expects string, mixed given\.$#'
1144+
message: '#^Parameter \#1 \$path of method PhpMyAdmin\\Config\\Validator\:\:validateTrustedProxies\(\) expects string, mixed given\.$#'
11571145
identifier: argument.type
11581146
count: 1
11591147
path: src/Config/Validator.php
11601148

11611149
-
1162-
message: '#^Parameter \#1 \$path of static method PhpMyAdmin\\Config\\Validator\:\:validateUpperBound\(\) expects string, mixed given\.$#'
1150+
message: '#^Parameter \#1 \$path of method PhpMyAdmin\\Config\\Validator\:\:validateUpperBound\(\) expects string, mixed given\.$#'
11631151
identifier: argument.type
11641152
count: 1
11651153
path: src/Config/Validator.php
@@ -1171,7 +1159,7 @@ parameters:
11711159
path: src/Config/Validator.php
11721160

11731161
-
1174-
message: '#^Parameter \#2 \$port of static method PhpMyAdmin\\Config\\Validator\:\:testDBConnection\(\) expects int\|string, mixed given\.$#'
1162+
message: '#^Parameter \#2 \$port of method PhpMyAdmin\\Config\\Validator\:\:testDBConnection\(\) expects int\|string, mixed given\.$#'
11751163
identifier: argument.type
11761164
count: 2
11771165
path: src/Config/Validator.php
@@ -1189,7 +1177,7 @@ parameters:
11891177
path: src/Config/Validator.php
11901178

11911179
-
1192-
message: '#^Parameter \#3 \$socket of static method PhpMyAdmin\\Config\\Validator\:\:testDBConnection\(\) expects string, mixed given\.$#'
1180+
message: '#^Parameter \#3 \$socket of method PhpMyAdmin\\Config\\Validator\:\:testDBConnection\(\) expects string, mixed given\.$#'
11931181
identifier: argument.type
11941182
count: 2
11951183
path: src/Config/Validator.php
@@ -1201,13 +1189,13 @@ parameters:
12011189
path: src/Config/Validator.php
12021190

12031191
-
1204-
message: '#^Parameter \#4 \$user of static method PhpMyAdmin\\Config\\Validator\:\:testDBConnection\(\) expects string, mixed given\.$#'
1192+
message: '#^Parameter \#4 \$user of method PhpMyAdmin\\Config\\Validator\:\:testDBConnection\(\) expects string, mixed given\.$#'
12051193
identifier: argument.type
12061194
count: 2
12071195
path: src/Config/Validator.php
12081196

12091197
-
1210-
message: '#^Parameter \#5 \$pass of static method PhpMyAdmin\\Config\\Validator\:\:testDBConnection\(\) expects string, mixed given\.$#'
1198+
message: '#^Parameter \#5 \$pass of method PhpMyAdmin\\Config\\Validator\:\:testDBConnection\(\) expects string, mixed given\.$#'
12111199
identifier: argument.type
12121200
count: 2
12131201
path: src/Config/Validator.php
@@ -1219,7 +1207,7 @@ parameters:
12191207
path: src/Config/Validator.php
12201208

12211209
-
1222-
message: '#^Static property PhpMyAdmin\\Config\\Validator\:\:\$validators \(array\<mixed\>\|null\) does not accept mixed\.$#'
1210+
message: '#^Property PhpMyAdmin\\Config\\Validator\:\:\$validators \(array\<array\<mixed\>\|string\>\) does not accept mixed\.$#'
12231211
identifier: assign.propertyType
12241212
count: 1
12251213
path: src/Config/Validator.php

psalm-baseline.xml

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@
242242
<code><![CDATA[$ip]]></code>
243243
<code><![CDATA[$userPrefsDisallow ?? []]]></code>
244244
<code><![CDATA[$val]]></code>
245-
<code><![CDATA[$validators[$path]]]></code>
246245
<code><![CDATA[$value]]></code>
247246
</MixedArgument>
248247
<MixedArgumentTypeCoercion>
@@ -497,39 +496,34 @@
497496
<code><![CDATA[$k]]></code>
498497
</MixedArgumentTypeCoercion>
499498
<MixedArrayAccess>
500-
<code><![CDATA[self::$validators[$field]]]></code>
499+
<code><![CDATA[$this->validators[$field]]]></code>
501500
</MixedArrayAccess>
502501
<MixedArrayAssignment>
503-
<code><![CDATA[self::$validators[$field]]]></code>
502+
<code><![CDATA[$this->validators[$field]]]></code>
504503
</MixedArrayAssignment>
505504
<MixedArrayOffset>
506-
<code><![CDATA[self::$validators[$field]]]></code>
507-
<code><![CDATA[self::$validators[$field]]]></code>
508-
<code><![CDATA[self::$validators[$field]]]></code>
505+
<code><![CDATA[$this->validators[$field]]]></code>
506+
<code><![CDATA[$this->validators[$field]]]></code>
507+
<code><![CDATA[$this->validators[$field]]]></code>
509508
</MixedArrayOffset>
510509
<MixedAssignment>
511510
<code><![CDATA[$arguments[$k2]]]></code>
512511
<code><![CDATA[$field]]></code>
513512
<code><![CDATA[$ip]]></code>
514513
<code><![CDATA[$password]]></code>
515-
<code><![CDATA[$uv]]></code>
514+
<code><![CDATA[$this->validators]]></code>
515+
<code><![CDATA[$this->validators]]></code>
516516
<code><![CDATA[$uvList]]></code>
517517
<code><![CDATA[$uv[$i]]]></code>
518518
<code><![CDATA[$uvs]]></code>
519519
<code><![CDATA[$v]]></code>
520520
<code><![CDATA[$v]]></code>
521521
<code><![CDATA[$validator]]></code>
522522
<code><![CDATA[$vname]]></code>
523-
<code><![CDATA[self::$validators]]></code>
524523
</MixedAssignment>
525524
<MixedOperand>
526525
<code><![CDATA[$ip]]></code>
527526
</MixedOperand>
528-
<MixedReturnStatement>
529-
<code><![CDATA[self::$validators]]></code>
530-
<code><![CDATA[self::$validators]]></code>
531-
<code><![CDATA[self::$validators]]></code>
532-
</MixedReturnStatement>
533527
<PossiblyInvalidArgument>
534528
<code><![CDATA[$k2]]></code>
535529
<code><![CDATA[$k2]]></code>
@@ -538,36 +532,33 @@
538532
<code><![CDATA[$k2]]></code>
539533
<code><![CDATA[$k2]]></code>
540534
</PossiblyInvalidCast>
541-
<ReferenceReusedFromConfusingScope>
542-
<code><![CDATA[$vid]]></code>
543-
</ReferenceReusedFromConfusingScope>
544535
<RiskyTruthyFalsyComparison>
545536
<code><![CDATA[empty($errorList)]]></code>
546537
<code><![CDATA[empty($values['Servers/1/controlpass'])]]></code>
547538
<code><![CDATA[empty($values['Servers/1/controluser'])]]></code>
548539
<code><![CDATA[mb_strpos($k2, '/')]]></code>
549540
</RiskyTruthyFalsyComparison>
550541
<TooFewArguments>
551-
<code><![CDATA[self::validateByRegex(...$args)]]></code>
552-
<code><![CDATA[self::validateByRegex(...$args)]]></code>
553-
<code><![CDATA[self::validateByRegex(...$args)]]></code>
554-
<code><![CDATA[self::validateNonNegativeNumber(...$args)]]></code>
555-
<code><![CDATA[self::validateNonNegativeNumber(...$args)]]></code>
556-
<code><![CDATA[self::validatePMAStorage(...$args)]]></code>
557-
<code><![CDATA[self::validatePMAStorage(...$args)]]></code>
558-
<code><![CDATA[self::validatePortNumber(...$args)]]></code>
559-
<code><![CDATA[self::validatePortNumber(...$args)]]></code>
560-
<code><![CDATA[self::validatePositiveNumber(...$args)]]></code>
561-
<code><![CDATA[self::validatePositiveNumber(...$args)]]></code>
562-
<code><![CDATA[self::validateRegex(...$args)]]></code>
563-
<code><![CDATA[self::validateRegex(...$args)]]></code>
564-
<code><![CDATA[self::validateServer(...$args)]]></code>
565-
<code><![CDATA[self::validateServer(...$args)]]></code>
566-
<code><![CDATA[self::validateTrustedProxies(...$args)]]></code>
567-
<code><![CDATA[self::validateTrustedProxies(...$args)]]></code>
568-
<code><![CDATA[self::validateUpperBound(...$args)]]></code>
569-
<code><![CDATA[self::validateUpperBound(...$args)]]></code>
570-
<code><![CDATA[self::validateUpperBound(...$args)]]></code>
542+
<code><![CDATA[validateByRegex]]></code>
543+
<code><![CDATA[validateByRegex]]></code>
544+
<code><![CDATA[validateByRegex]]></code>
545+
<code><![CDATA[validateNonNegativeNumber]]></code>
546+
<code><![CDATA[validateNonNegativeNumber]]></code>
547+
<code><![CDATA[validatePMAStorage]]></code>
548+
<code><![CDATA[validatePMAStorage]]></code>
549+
<code><![CDATA[validatePortNumber]]></code>
550+
<code><![CDATA[validatePortNumber]]></code>
551+
<code><![CDATA[validatePositiveNumber]]></code>
552+
<code><![CDATA[validatePositiveNumber]]></code>
553+
<code><![CDATA[validateRegex]]></code>
554+
<code><![CDATA[validateRegex]]></code>
555+
<code><![CDATA[validateServer]]></code>
556+
<code><![CDATA[validateServer]]></code>
557+
<code><![CDATA[validateTrustedProxies]]></code>
558+
<code><![CDATA[validateTrustedProxies]]></code>
559+
<code><![CDATA[validateUpperBound]]></code>
560+
<code><![CDATA[validateUpperBound]]></code>
561+
<code><![CDATA[validateUpperBound]]></code>
571562
</TooFewArguments>
572563
</file>
573564
<file src="src/ConfigStorage/Relation.php">

src/Config/FormDisplay.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ class FormDisplay
9999

100100
private static bool $hasCheckPageRefresh = false;
101101

102+
private Validator $validator;
103+
102104
public function __construct(private ConfigFile $configFile)
103105
{
104106
$config = Config::getInstance();
105107
$this->formDisplayTemplate = new FormDisplayTemplate($config);
106108
$this->isSetupScript = $config->isSetup();
107-
// initialize validators
108-
Validator::getValidators($this->configFile);
109+
$this->validator = new Validator($this->configFile);
109110
}
110111

111112
/**
@@ -179,7 +180,7 @@ private function validate(): void
179180
}
180181

181182
// run validation
182-
$errors = Validator::validate($this->configFile, $paths, $values, false);
183+
$errors = $this->validator->validate($paths, $values, false);
183184

184185
// change error keys from canonical paths to work paths
185186
if (is_array($errors) && $errors !== []) {
@@ -246,7 +247,7 @@ public function getDisplay(
246247
// user preferences
247248
$this->loadUserprefsInfo();
248249

249-
$validators = Validator::getValidators($this->configFile);
250+
$validators = $this->validator->getValidators();
250251
$forms = [];
251252

252253
foreach ($this->forms as $key => $form) {

0 commit comments

Comments
 (0)