Skip to content

Commit d5f6712

Browse files
committed
Add specific type declarations to arrays
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent 41cea26 commit d5f6712

23 files changed

+144
-318
lines changed

phpcs.xml.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515

1616
<rule ref="PhpMyAdmin">
1717
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
18-
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
19-
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
2018
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
21-
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
2219
<exclude name="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps"/>
2320
</rule>
2421

phpstan-baseline.neon

Lines changed: 44 additions & 169 deletions
Large diffs are not rendered by default.

psalm-baseline.xml

Lines changed: 52 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
<MixedArrayOffset occurrences="1">
1616
<code>Parser::$STATEMENT_PARSERS[$token-&gt;value]</code>
1717
</MixedArrayOffset>
18-
<MixedPropertyTypeCoercion occurrences="1">
19-
<code>$unknown</code>
20-
</MixedPropertyTypeCoercion>
2118
<MoreSpecificImplementedParamType occurrences="1">
2219
<code>$component</code>
2320
</MoreSpecificImplementedParamType>
@@ -45,10 +42,6 @@
4542
</PossiblyInvalidPropertyFetch>
4643
</file>
4744
<file src="src/Components/ArrayObj.php">
48-
<MixedArgumentTypeCoercion occurrences="2">
49-
<code>$component-&gt;raw</code>
50-
<code>$component-&gt;values</code>
51-
</MixedArgumentTypeCoercion>
5245
<MixedAssignment occurrences="1">
5346
<code>$ret[]</code>
5447
</MixedAssignment>
@@ -83,13 +76,15 @@
8376
<InvalidOperand occurrences="1">
8477
<code>! $token-&gt;flags</code>
8578
</InvalidOperand>
79+
<InvalidPropertyAssignmentValue occurrences="3">
80+
<code>$ret-&gt;compare_values</code>
81+
<code>$ret-&gt;results</code>
82+
<code>$ret-&gt;results</code>
83+
</InvalidPropertyAssignmentValue>
8684
<MixedAssignment occurrences="1">
8785
<code>$ret-&gt;alias</code>
8886
</MixedAssignment>
89-
<MixedOperand occurrences="4">
90-
<code>$component-&gt;compare_values[$i]</code>
91-
<code>$component-&gt;results[$i]</code>
92-
<code>$component-&gt;results[$i]</code>
87+
<MixedOperand occurrences="1">
9388
<code>$token-&gt;value</code>
9489
</MixedOperand>
9590
<MoreSpecificImplementedParamType occurrences="1">
@@ -135,9 +130,6 @@
135130
</PossiblyNullOperand>
136131
</file>
137132
<file src="src/Components/DataType.php">
138-
<MixedArgumentTypeCoercion occurrences="1">
139-
<code>$component-&gt;parameters</code>
140-
</MixedArgumentTypeCoercion>
141133
<MoreSpecificImplementedParamType occurrences="1">
142134
<code>$component</code>
143135
</MoreSpecificImplementedParamType>
@@ -158,9 +150,6 @@
158150
<InvalidArgument occurrences="1">
159151
<code>$options['breakOnParentheses']</code>
160152
</InvalidArgument>
161-
<MixedArgumentTypeCoercion occurrences="1">
162-
<code>Context::escape($fields)</code>
163-
</MixedArgumentTypeCoercion>
164153
<MixedArrayOffset occurrences="2">
165154
<code>Parser::$STATEMENT_PARSERS[$token-&gt;keyword]</code>
166155
<code>self::$ALLOWED_KEYWORDS[$token-&gt;keyword]</code>
@@ -180,6 +169,9 @@
180169
<MoreSpecificImplementedParamType occurrences="1">
181170
<code>$component</code>
182171
</MoreSpecificImplementedParamType>
172+
<PossiblyInvalidArgument occurrences="1">
173+
<code>Context::escape($fields)</code>
174+
</PossiblyInvalidArgument>
183175
<PossiblyInvalidOperand occurrences="1">
184176
<code>Context::escape($component-&gt;alias)</code>
185177
</PossiblyInvalidOperand>
@@ -240,9 +232,6 @@
240232
</PossiblyNullPropertyAssignmentValue>
241233
</file>
242234
<file src="src/Components/IndexHint.php">
243-
<MixedArgumentTypeCoercion occurrences="1">
244-
<code>$component-&gt;indexes</code>
245-
</MixedArgumentTypeCoercion>
246235
<MixedAssignment occurrences="2">
247236
<code>$expr-&gt;type</code>
248237
<code>$expr-&gt;type</code>
@@ -264,15 +253,9 @@
264253
<code>$token-&gt;value</code>
265254
<code>$token-&gt;value</code>
266255
</MixedArgument>
267-
<MixedArgumentTypeCoercion occurrences="1">
268-
<code>$component-&gt;columns</code>
269-
</MixedArgumentTypeCoercion>
270256
<MixedAssignment occurrences="1">
271257
<code>$ret-&gt;dest</code>
272258
</MixedAssignment>
273-
<MixedPropertyTypeCoercion occurrences="1">
274-
<code>$values</code>
275-
</MixedPropertyTypeCoercion>
276259
<MoreSpecificImplementedParamType occurrences="1">
277260
<code>$component</code>
278261
</MoreSpecificImplementedParamType>
@@ -336,9 +319,6 @@
336319
<code>$ret-&gt;name</code>
337320
<code>$ret-&gt;type</code>
338321
</MixedAssignment>
339-
<MixedPropertyTypeCoercion occurrences="1">
340-
<code>$columns</code>
341-
</MixedPropertyTypeCoercion>
342322
<MoreSpecificImplementedParamType occurrences="1">
343323
<code>$component</code>
344324
</MoreSpecificImplementedParamType>
@@ -442,6 +422,16 @@
442422
<code>$ret-&gt;options[$lastOptionId]['expr']</code>
443423
<code>$ret-&gt;options[$lastOptionId]['value']</code>
444424
</MixedOperand>
425+
<MixedPropertyTypeCoercion occurrences="8">
426+
<code>$ret-&gt;options</code>
427+
<code>$ret-&gt;options</code>
428+
<code>$ret-&gt;options</code>
429+
<code>$ret-&gt;options</code>
430+
<code>$ret-&gt;options</code>
431+
<code>$ret-&gt;options</code>
432+
<code>$ret-&gt;options</code>
433+
<code>$ret-&gt;options</code>
434+
</MixedPropertyTypeCoercion>
445435
<MoreSpecificImplementedParamType occurrences="1">
446436
<code>$component</code>
447437
</MoreSpecificImplementedParamType>
@@ -531,12 +521,12 @@
531521
</UnusedVariable>
532522
</file>
533523
<file src="src/Components/Reference.php">
534-
<MixedArgumentTypeCoercion occurrences="1">
535-
<code>Context::escape($component-&gt;columns)</code>
536-
</MixedArgumentTypeCoercion>
537524
<MoreSpecificImplementedParamType occurrences="1">
538525
<code>$component</code>
539526
</MoreSpecificImplementedParamType>
527+
<PossiblyInvalidArgument occurrences="1">
528+
<code>Context::escape($component-&gt;columns)</code>
529+
</PossiblyInvalidArgument>
540530
<PossiblyInvalidPropertyFetch occurrences="1">
541531
<code>ArrayObj::parse($parser, $list)-&gt;values</code>
542532
</PossiblyInvalidPropertyFetch>
@@ -588,11 +578,13 @@
588578
<InvalidPropertyFetch occurrences="1">
589579
<code>$context::$KEYWORDS</code>
590580
</InvalidPropertyFetch>
591-
<MixedArgument occurrences="1">
592-
<code>$value</code>
593-
</MixedArgument>
594-
<MixedAssignment occurrences="3">
595-
<code>$value</code>
581+
<InvalidReturnStatement occurrences="1">
582+
<code>$str</code>
583+
</InvalidReturnStatement>
584+
<InvalidReturnType occurrences="1">
585+
<code>string|string[]</code>
586+
</InvalidReturnType>
587+
<MixedAssignment occurrences="2">
596588
<code>self::$KEYWORDS</code>
597589
<code>static::$MODE</code>
598590
</MixedAssignment>
@@ -849,12 +841,13 @@
849841
<code>$class === null</code>
850842
<code>count($clauses) === 0</code>
851843
</DocblockTypeContradiction>
844+
<InvalidArgument occurrences="2">
845+
<code>$built[$field]</code>
846+
<code>$parsedClauses[$token-&gt;value]</code>
847+
</InvalidArgument>
852848
<InvalidStringClass occurrences="1">
853849
<code>$class::parse($parser, $list, $options)</code>
854850
</InvalidStringClass>
855-
<MixedArgumentTypeCoercion occurrences="1">
856-
<code>$options</code>
857-
</MixedArgumentTypeCoercion>
858851
<MixedArrayOffset occurrences="8">
859852
<code>$parsedClauses[$token-&gt;value]</code>
860853
<code>$parsedClauses[$token-&gt;value]</code>
@@ -914,9 +907,6 @@
914907
</PossiblyNullIterator>
915908
</file>
916909
<file src="src/Statements/CallStatement.php">
917-
<MixedArgumentTypeCoercion occurrences="1">
918-
<code>$this-&gt;call-&gt;parameters-&gt;raw</code>
919-
</MixedArgumentTypeCoercion>
920910
<PossiblyNullOperand occurrences="1">
921911
<code>$this-&gt;call-&gt;name</code>
922912
</PossiblyNullOperand>
@@ -1245,18 +1235,10 @@
12451235
<code>self::$INLINE_CLAUSES[$lastClause]</code>
12461236
<code>self::$SHORT_CLAUSES[$lastClause]</code>
12471237
</MixedArrayTypeCoercion>
1248-
<MixedAssignment occurrences="15">
1249-
<code>$blocksIndentation[]</code>
1250-
<code>$blocksIndentation[]</code>
1238+
<MixedAssignment occurrences="7">
12511239
<code>$blocksLineEndings[]</code>
12521240
<code>$format</code>
12531241
<code>$func</code>
1254-
<code>$indent</code>
1255-
<code>$indent</code>
1256-
<code>$indent</code>
1257-
<code>$indent</code>
1258-
<code>$indent</code>
1259-
<code>$indent</code>
12601242
<code>$lastClause</code>
12611243
<code>$lineEnded</code>
12621244
<code>$prev</code>
@@ -1268,14 +1250,10 @@
12681250
<MixedInferredReturnType occurrences="1">
12691251
<code>string</code>
12701252
</MixedInferredReturnType>
1271-
<MixedOperand occurrences="8">
1253+
<MixedOperand occurrences="4">
12721254
<code>$format['cli']</code>
12731255
<code>$format['flags']</code>
12741256
<code>$format['html']</code>
1275-
<code>$indent</code>
1276-
<code>$indent</code>
1277-
<code>$indent</code>
1278-
<code>$indent</code>
12791257
<code>array_pop($blocksLineEndings)</code>
12801258
</MixedOperand>
12811259
<MixedReturnStatement occurrences="1">
@@ -1315,18 +1293,11 @@
13151293
<code>$clauses[$token-&gt;keyword]</code>
13161294
<code>$clauses[$token-&gt;keyword]</code>
13171295
</MixedArrayTypeCoercion>
1318-
<MixedAssignment occurrences="6">
1319-
<code>$currIdx</code>
1296+
<MixedAssignment occurrences="3">
13201297
<code>$expr</code>
13211298
<code>$expressions[]</code>
1322-
<code>$firstClauseIdx</code>
1323-
<code>$lastClauseIdx</code>
13241299
<code>$rename</code>
13251300
</MixedAssignment>
1326-
<MixedOperand occurrences="2">
1327-
<code>$clauses[$type]</code>
1328-
<code>$clauses[$type]</code>
1329-
</MixedOperand>
13301301
<MixedPropertyAssignment occurrences="2">
13311302
<code>$expr</code>
13321303
<code>$expr</code>
@@ -1361,13 +1332,10 @@
13611332
</PossiblyNullReference>
13621333
</file>
13631334
<file src="src/Utils/Routine.php">
1364-
<MixedArgumentTypeCoercion occurrences="6">
1335+
<MixedArgumentTypeCoercion occurrences="3">
13651336
<code>$options</code>
13661337
<code>$options</code>
1367-
<code>$param-&gt;type-&gt;parameters</code>
1368-
<code>$param-&gt;type-&gt;parameters</code>
13691338
<code>$retval['opts'][$idx]</code>
1370-
<code>$type-&gt;parameters</code>
13711339
</MixedArgumentTypeCoercion>
13721340
<MixedArrayAccess occurrences="3">
13731341
<code>$opt['value']</code>
@@ -1406,16 +1374,17 @@
14061374
</PossiblyNullReference>
14071375
</file>
14081376
<file src="src/Utils/Tokens.php">
1377+
<InvalidArgument occurrences="1">
1378+
<code>$find[$k]</code>
1379+
</InvalidArgument>
14091380
<InvalidReturnStatement occurrences="1">
14101381
<code>$isList ? new TokensList($newList) : TokensList::build($newList)</code>
14111382
</InvalidReturnStatement>
14121383
<InvalidReturnType occurrences="1">
14131384
<code>TokensList</code>
14141385
</InvalidReturnType>
1415-
<MixedArgument occurrences="3">
1416-
<code>$find[$k]</code>
1386+
<MixedArgument occurrences="1">
14171387
<code>$list-&gt;tokens[$j]</code>
1418-
<code>$pattern['value_str']</code>
14191388
</MixedArgument>
14201389
<MixedArgumentTypeCoercion occurrences="2">
14211390
<code>$newList</code>
@@ -1428,22 +1397,21 @@
14281397
<code>$list-&gt;tokens[$j]</code>
14291398
<code>$list-&gt;tokens[$j]</code>
14301399
</MixedArrayAccess>
1431-
<MixedAssignment occurrences="4">
1432-
<code>$newList[]</code>
1400+
<MixedAssignment occurrences="2">
14331401
<code>$newList[]</code>
14341402
<code>$newList[]</code>
1435-
<code>$token</code>
14361403
</MixedAssignment>
1437-
<MixedOperand occurrences="1">
1438-
<code>$pattern['flags']</code>
1439-
</MixedOperand>
14401404
<MixedPropertyFetch occurrences="2">
14411405
<code>$list-&gt;tokens[$i]-&gt;type</code>
14421406
<code>$list-&gt;tokens[$j]-&gt;type</code>
14431407
</MixedPropertyFetch>
1444-
<PossiblyInvalidArgument occurrences="1">
1408+
<PossiblyInvalidArgument occurrences="2">
14451409
<code>$list</code>
1410+
<code>$pattern['value_str']</code>
14461411
</PossiblyInvalidArgument>
1412+
<PossiblyInvalidOperand occurrences="1">
1413+
<code>$pattern['flags']</code>
1414+
</PossiblyInvalidOperand>
14471415
<PossiblyInvalidPropertyFetch occurrences="2">
14481416
<code>$list-&gt;count</code>
14491417
<code>$list-&gt;tokens</code>
@@ -1627,4 +1595,9 @@
16271595
<code>$parser-&gt;statements[0]</code>
16281596
</ArgumentTypeCoercion>
16291597
</file>
1598+
<file src="tests/Utils/TokensTest.php">
1599+
<InvalidArgument occurrences="1">
1600+
<code>$find</code>
1601+
</InvalidArgument>
1602+
</file>
16301603
</files>

src/Components/AlterOperation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class AlterOperation extends Component
208208
/**
209209
* @param OptionsArray $options options of alter operation
210210
* @param Expression $field altered field
211-
* @param array $unknown unparsed tokens found at the end of operation
211+
* @param Token[] $unknown unparsed tokens found at the end of operation
212212
*/
213213
public function __construct(
214214
$options = null,

src/Components/ArrayObj.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ class ArrayObj extends Component
2727
/**
2828
* The array that contains the unprocessed value of each token.
2929
*
30-
* @var array
30+
* @var string[]
3131
*/
3232
public $raw = [];
3333

3434
/**
3535
* The array that contains the processed value of each token.
3636
*
37-
* @var array
37+
* @var string[]
3838
*/
3939
public $values = [];
4040

4141
/**
42-
* @param array $raw the unprocessed values
43-
* @param array $values the processed values
42+
* @param string[] $raw the unprocessed values
43+
* @param string[] $values the processed values
4444
*/
4545
public function __construct(array $raw = [], array $values = [])
4646
{

src/Components/CaseExpression.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ class CaseExpression extends Component
3939
/**
4040
* The results matching with the WHEN clauses.
4141
*
42-
* @var array
42+
* @var Expression[]
4343
*/
4444
public $results = [];
4545

4646
/**
4747
* The values to be compared against.
4848
*
49-
* @var array
49+
* @var Expression[]
5050
*/
5151
public $compare_values = [];
5252

0 commit comments

Comments
 (0)