Skip to content

Commit 22c50b5

Browse files
committed
Add type declarations to some class properties
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent 4270681 commit 22c50b5

20 files changed

+143
-341
lines changed

phpstan-baseline.neon

Lines changed: 25 additions & 175 deletions
Large diffs are not rendered by default.

psalm-baseline.xml

Lines changed: 32 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@
8383
<InvalidOperand occurrences="1">
8484
<code>! $token-&gt;flags</code>
8585
</InvalidOperand>
86-
<MixedArgument occurrences="1">
87-
<code>$component-&gt;conditions[$i]</code>
88-
</MixedArgument>
8986
<MixedAssignment occurrences="1">
9087
<code>$ret-&gt;alias</code>
9188
</MixedAssignment>
@@ -103,15 +100,9 @@
103100
</PossiblyInvalidOperand>
104101
</file>
105102
<file src="src/Components/Condition.php">
106-
<MixedArgument occurrences="1">
107-
<code>$token-&gt;value</code>
108-
</MixedArgument>
109103
<MixedArrayOffset occurrences="1">
110104
<code>static::$ALLOWED_KEYWORDS[$token-&gt;value]</code>
111105
</MixedArrayOffset>
112-
<MixedArrayTypeCoercion occurrences="1">
113-
<code>static::$ALLOWED_KEYWORDS[$token-&gt;value]</code>
114-
</MixedArrayTypeCoercion>
115106
<MixedInferredReturnType occurrences="1">
116107
<code>string</code>
117108
</MixedInferredReturnType>
@@ -312,10 +303,6 @@
312303
<code>static::$JOINS[$token-&gt;keyword]</code>
313304
<code>static::$JOINS[$token-&gt;keyword]</code>
314305
</MixedArrayTypeCoercion>
315-
<MixedAssignment occurrences="2">
316-
<code>$expr-&gt;type</code>
317-
<code>$expr-&gt;type</code>
318-
</MixedAssignment>
319306
<MoreSpecificImplementedParamType occurrences="1">
320307
<code>$component</code>
321308
</MoreSpecificImplementedParamType>
@@ -595,6 +582,9 @@
595582
</MoreSpecificImplementedParamType>
596583
</file>
597584
<file src="src/Context.php">
585+
<InvalidPropertyAssignmentValue occurrences="1">
586+
<code>[]</code>
587+
</InvalidPropertyAssignmentValue>
598588
<InvalidPropertyFetch occurrences="1">
599589
<code>$context::$KEYWORDS</code>
600590
</InvalidPropertyFetch>
@@ -606,95 +596,47 @@
606596
<code>self::$KEYWORDS</code>
607597
<code>static::$MODE</code>
608598
</MixedAssignment>
609-
<MixedInferredReturnType occurrences="2">
610-
<code>int|null</code>
611-
<code>int|null</code>
612-
</MixedInferredReturnType>
613-
<MixedOperand occurrences="2">
599+
<MixedOperand occurrences="1">
614600
<code>constant('static::SQL_MODE_' . $m)</code>
615-
<code>static::$KEYWORDS[$str]</code>
616601
</MixedOperand>
617-
<MixedReturnStatement occurrences="2">
618-
<code>static::$KEYWORDS[$str]</code>
619-
<code>static::$OPERATORS[$str]</code>
620-
</MixedReturnStatement>
621602
</file>
622603
<file src="src/Contexts/ContextMariaDb100000.php">
623-
<NonInvariantDocblockPropertyType occurrences="1">
624-
<code>$KEYWORDS</code>
625-
</NonInvariantDocblockPropertyType>
626604
<PropertyTypeCoercion occurrences="1"/>
627605
</file>
628606
<file src="src/Contexts/ContextMariaDb100100.php">
629-
<NonInvariantDocblockPropertyType occurrences="1">
630-
<code>$KEYWORDS</code>
631-
</NonInvariantDocblockPropertyType>
632607
<PropertyTypeCoercion occurrences="1"/>
633608
</file>
634609
<file src="src/Contexts/ContextMariaDb100200.php">
635-
<NonInvariantDocblockPropertyType occurrences="1">
636-
<code>$KEYWORDS</code>
637-
</NonInvariantDocblockPropertyType>
638610
<PropertyTypeCoercion occurrences="1"/>
639611
</file>
640612
<file src="src/Contexts/ContextMariaDb100300.php">
641-
<NonInvariantDocblockPropertyType occurrences="1">
642-
<code>$KEYWORDS</code>
643-
</NonInvariantDocblockPropertyType>
644613
<PropertyTypeCoercion occurrences="1"/>
645614
</file>
646615
<file src="src/Contexts/ContextMariaDb100400.php">
647-
<NonInvariantDocblockPropertyType occurrences="1">
648-
<code>$KEYWORDS</code>
649-
</NonInvariantDocblockPropertyType>
650616
<PropertyTypeCoercion occurrences="1"/>
651617
</file>
652618
<file src="src/Contexts/ContextMariaDb100500.php">
653-
<NonInvariantDocblockPropertyType occurrences="1">
654-
<code>$KEYWORDS</code>
655-
</NonInvariantDocblockPropertyType>
656619
<PropertyTypeCoercion occurrences="1"/>
657620
</file>
658621
<file src="src/Contexts/ContextMariaDb100600.php">
659-
<NonInvariantDocblockPropertyType occurrences="1">
660-
<code>$KEYWORDS</code>
661-
</NonInvariantDocblockPropertyType>
662622
<PropertyTypeCoercion occurrences="1"/>
663623
</file>
664624
<file src="src/Contexts/ContextMySql50000.php">
665-
<NonInvariantDocblockPropertyType occurrences="1">
666-
<code>$KEYWORDS</code>
667-
</NonInvariantDocblockPropertyType>
668625
<PropertyTypeCoercion occurrences="1"/>
669626
</file>
670627
<file src="src/Contexts/ContextMySql50100.php">
671-
<NonInvariantDocblockPropertyType occurrences="1">
672-
<code>$KEYWORDS</code>
673-
</NonInvariantDocblockPropertyType>
674628
<PropertyTypeCoercion occurrences="1"/>
675629
</file>
676630
<file src="src/Contexts/ContextMySql50500.php">
677-
<NonInvariantDocblockPropertyType occurrences="1">
678-
<code>$KEYWORDS</code>
679-
</NonInvariantDocblockPropertyType>
680631
<PropertyTypeCoercion occurrences="1"/>
681632
</file>
682633
<file src="src/Contexts/ContextMySql50600.php">
683-
<NonInvariantDocblockPropertyType occurrences="1">
684-
<code>$KEYWORDS</code>
685-
</NonInvariantDocblockPropertyType>
686634
<PropertyTypeCoercion occurrences="1"/>
687635
</file>
688636
<file src="src/Contexts/ContextMySql50700.php">
689-
<NonInvariantDocblockPropertyType occurrences="1">
690-
<code>$KEYWORDS</code>
691-
</NonInvariantDocblockPropertyType>
692637
<PropertyTypeCoercion occurrences="1"/>
693638
</file>
694639
<file src="src/Contexts/ContextMySql80000.php">
695-
<NonInvariantDocblockPropertyType occurrences="1">
696-
<code>$KEYWORDS</code>
697-
</NonInvariantDocblockPropertyType>
698640
<PropertyTypeCoercion occurrences="1"/>
699641
</file>
700642
<file src="src/Exceptions/ParserException.php">
@@ -903,19 +845,13 @@
903845
</PossiblyNullReference>
904846
</file>
905847
<file src="src/Statement.php">
906-
<DocblockTypeContradiction occurrences="1">
848+
<DocblockTypeContradiction occurrences="2">
849+
<code>$class === null</code>
907850
<code>count($clauses) === 0</code>
908851
</DocblockTypeContradiction>
909-
<MixedArgument occurrences="1">
910-
<code>$options</code>
911-
</MixedArgument>
912-
<MixedArrayAccess occurrences="5">
913-
<code>Parser::$KEYWORD_PARSERS[$name]['class']</code>
914-
<code>Parser::$KEYWORD_PARSERS[$name]['field']</code>
915-
<code>Parser::$KEYWORD_PARSERS[$tokenValue]['class']</code>
916-
<code>Parser::$KEYWORD_PARSERS[$tokenValue]['field']</code>
917-
<code>Parser::$KEYWORD_PARSERS[$tokenValue]['options']</code>
918-
</MixedArrayAccess>
852+
<InvalidStringClass occurrences="1">
853+
<code>$class::parse($parser, $list, $options)</code>
854+
</InvalidStringClass>
919855
<MixedArrayOffset occurrences="8">
920856
<code>$parsedClauses[$token-&gt;value]</code>
921857
<code>$parsedClauses[$token-&gt;value]</code>
@@ -930,21 +866,24 @@
930866
<code>Parser::$KEYWORD_PARSERS[$tokenValue]</code>
931867
<code>Parser::$STATEMENT_PARSERS[$token-&gt;keyword]</code>
932868
</MixedArrayTypeCoercion>
933-
<MixedAssignment occurrences="4">
934-
<code>$class</code>
935-
<code>$field</code>
936-
<code>$options</code>
869+
<MixedAssignment occurrences="1">
937870
<code>$tokenValue</code>
938871
</MixedAssignment>
939-
<MixedMethodCall occurrences="1">
940-
<code>$class::parse($parser, $list, $options)</code>
941-
</MixedMethodCall>
942872
<MixedOperand occurrences="1">
943873
<code>$class::build($this-&gt;$field)</code>
944874
</MixedOperand>
945875
<PossiblyNullPropertyFetch occurrences="1">
946876
<code>$list-&gt;offsetGet($list-&gt;idx)-&gt;type</code>
947877
</PossiblyNullPropertyFetch>
878+
<PossiblyUndefinedArrayOffset occurrences="4">
879+
<code>Parser::$KEYWORD_PARSERS[$name]['class']</code>
880+
<code>Parser::$KEYWORD_PARSERS[$name]['field']</code>
881+
<code>Parser::$KEYWORD_PARSERS[$tokenValue]['class']</code>
882+
<code>Parser::$KEYWORD_PARSERS[$tokenValue]['field']</code>
883+
</PossiblyUndefinedArrayOffset>
884+
<RedundantConditionGivenDocblockType occurrences="1">
885+
<code>$class !== null</code>
886+
</RedundantConditionGivenDocblockType>
948887
<TypeDoesNotContainType occurrences="1">
949888
<code>count($clauses) === 0</code>
950889
</TypeDoesNotContainType>
@@ -1226,9 +1165,6 @@
12261165
</RedundantConditionGivenDocblockType>
12271166
</file>
12281167
<file src="src/Utils/BufferedQuery.php">
1229-
<MixedArgument occurrences="1">
1230-
<code>$this-&gt;options['delimiter']</code>
1231-
</MixedArgument>
12321168
<PossiblyNullOperand occurrences="1">
12331169
<code>$this-&gt;status</code>
12341170
</PossiblyNullOperand>
@@ -1249,9 +1185,10 @@
12491185
<code>$params['q']</code>
12501186
<code>$params['q']</code>
12511187
</MixedArgument>
1252-
<MixedArgumentTypeCoercion occurrences="2">
1188+
<MixedArgumentTypeCoercion occurrences="3">
12531189
<code>$idx</code>
12541190
<code>$output</code>
1191+
<code>['type' =&gt; $params['f']]</code>
12551192
</MixedArgumentTypeCoercion>
12561193
<MixedArrayAccess occurrences="5">
12571194
<code>$params['c']</code>
@@ -1296,17 +1233,15 @@
12961233
</MixedAssignment>
12971234
</file>
12981235
<file src="src/Utils/Formatter.php">
1299-
<MixedArgument occurrences="8">
1300-
<code>$options['formats']</code>
1236+
<MixedArgument occurrences="6">
13011237
<code>$text</code>
13021238
<code>$text</code>
13031239
<code>$text</code>
13041240
<code>$text</code>
13051241
<code>$text</code>
13061242
<code>$text</code>
1307-
<code>$this-&gt;options['indentation']</code>
13081243
</MixedArgument>
1309-
<MixedArrayAccess occurrences="12">
1244+
<MixedArrayAccess occurrences="8">
13101245
<code>$format['cli']</code>
13111246
<code>$format['cli']</code>
13121247
<code>$format['cli']</code>
@@ -1315,15 +1250,7 @@
13151250
<code>$format['function']</code>
13161251
<code>$format['html']</code>
13171252
<code>$format['type']</code>
1318-
<code>$new['flags']</code>
1319-
<code>$new['type']</code>
1320-
<code>$original['flags']</code>
1321-
<code>$original['type']</code>
13221253
</MixedArrayAccess>
1323-
<MixedArrayAssignment occurrences="2">
1324-
<code>$newFormats[$j][$name]</code>
1325-
<code>$newFormats[$j][$name]</code>
1326-
</MixedArrayAssignment>
13271254
<MixedArrayOffset occurrences="9">
13281255
<code>JoinKeyword::$JOINS[$list-&gt;tokens[$list-&gt;idx - 2]-&gt;value]</code>
13291256
<code>JoinKeyword::$JOINS[$list-&gt;tokens[$list-&gt;idx - 4]-&gt;value]</code>
@@ -1342,13 +1269,11 @@
13421269
<code>self::$INLINE_CLAUSES[$lastClause]</code>
13431270
<code>self::$SHORT_CLAUSES[$lastClause]</code>
13441271
</MixedArrayTypeCoercion>
1345-
<MixedAssignment occurrences="22">
1272+
<MixedAssignment occurrences="15">
13461273
<code>$blocksIndentation[]</code>
13471274
<code>$blocksIndentation[]</code>
13481275
<code>$blocksLineEndings[]</code>
13491276
<code>$format</code>
1350-
<code>$formats[$i]</code>
1351-
<code>$formats[]</code>
13521277
<code>$func</code>
13531278
<code>$indent</code>
13541279
<code>$indent</code>
@@ -1358,11 +1283,6 @@
13581283
<code>$indent</code>
13591284
<code>$lastClause</code>
13601285
<code>$lineEnded</code>
1361-
<code>$new</code>
1362-
<code>$new</code>
1363-
<code>$new</code>
1364-
<code>$options['parts_newline']</code>
1365-
<code>$original</code>
13661286
<code>$prev</code>
13671287
<code>$text</code>
13681288
</MixedAssignment>
@@ -1372,21 +1292,26 @@
13721292
<MixedInferredReturnType occurrences="1">
13731293
<code>string</code>
13741294
</MixedInferredReturnType>
1375-
<MixedOperand occurrences="10">
1295+
<MixedOperand occurrences="8">
13761296
<code>$format['cli']</code>
13771297
<code>$format['flags']</code>
13781298
<code>$format['html']</code>
13791299
<code>$indent</code>
13801300
<code>$indent</code>
13811301
<code>$indent</code>
13821302
<code>$indent</code>
1383-
<code>$options['parts_newline']</code>
1384-
<code>$this-&gt;options['line_ending']</code>
13851303
<code>array_pop($blocksLineEndings)</code>
13861304
</MixedOperand>
13871305
<MixedReturnStatement occurrences="1">
13881306
<code>$text</code>
13891307
</MixedReturnStatement>
1308+
<PossiblyInvalidArgument occurrences="2">
1309+
<code>$options['formats']</code>
1310+
<code>$this-&gt;options['indentation']</code>
1311+
</PossiblyInvalidArgument>
1312+
<PossiblyInvalidIterator occurrences="1">
1313+
<code>$this-&gt;options['formats']</code>
1314+
</PossiblyInvalidIterator>
13901315
<RedundantCondition occurrences="1">
13911316
<code>$curr-&gt;type === Token::TYPE_KEYWORD</code>
13921317
</RedundantCondition>

src/Components/AlterOperation.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class AlterOperation extends Component
2727
/**
2828
* All database options.
2929
*
30-
* @var array
30+
* @var array<string, int|array<int, int|string>>
31+
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
3132
*/
3233
public static $DB_OPTIONS = [
3334
'CHARACTER SET' => [
@@ -63,7 +64,8 @@ class AlterOperation extends Component
6364
/**
6465
* All table options.
6566
*
66-
* @var array
67+
* @var array<string, int|array<int, int|string>>
68+
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
6769
*/
6870
public static $TABLE_OPTIONS = [
6971
'ENGINE' => [
@@ -136,7 +138,8 @@ class AlterOperation extends Component
136138
/**
137139
* All user options.
138140
*
139-
* @var array
141+
* @var array<string, int|array<int, int|string>>
142+
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
140143
*/
141144
public static $USER_OPTIONS = [
142145
'ATTRIBUTE' => [
@@ -176,7 +179,8 @@ class AlterOperation extends Component
176179
/**
177180
* All view options.
178181
*
179-
* @var array
182+
* @var array<string, int|array<int, int|string>>
183+
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
180184
*/
181185
public static $VIEW_OPTIONS = ['AS' => 1];
182186

src/Components/CaseExpression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CaseExpression extends Component
3232
/**
3333
* The conditions in WHEN clauses.
3434
*
35-
* @var array
35+
* @var Condition[][]
3636
*/
3737
public $conditions = [];
3838

src/Components/Condition.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Condition extends Component
2727
/**
2828
* Logical operators that can be used to delimit expressions.
2929
*
30-
* @var array
30+
* @var string[]
3131
*/
3232
public static $DELIMITERS = [
3333
'&&',
@@ -40,7 +40,7 @@ class Condition extends Component
4040
/**
4141
* List of allowed reserved keywords in conditions.
4242
*
43-
* @var array
43+
* @var array<string, int>
4444
*/
4545
public static $ALLOWED_KEYWORDS = [
4646
'ALL' => 1,
@@ -67,7 +67,7 @@ class Condition extends Component
6767
/**
6868
* Identifiers recognized.
6969
*
70-
* @var array
70+
* @var array<int, mixed>
7171
*/
7272
public $identifiers = [];
7373

0 commit comments

Comments
 (0)