Skip to content

Commit b05c846

Browse files
Merge pull request #532 from kamil-tekiela/types-in-components
Add native property types in Statements
2 parents 2e71e97 + 282db99 commit b05c846

31 files changed

+117
-241
lines changed

phpstan-baseline.neon

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,12 @@ parameters:
541541
path: src/Statements/ExplainStatement.php
542542

543543
-
544-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\ExplainStatement\\:\\:\\$connectionId \\(int\\|null\\) does not accept mixed\\.$#"
544+
message: "#^Cannot cast mixed to string\\.$#"
545545
count: 1
546546
path: src/Statements/ExplainStatement.php
547547

548548
-
549-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\ExplainStatement\\:\\:\\$explainedColumn \\(string\\|null\\) does not accept mixed\\.$#"
549+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\ExplainStatement\\:\\:\\$connectionId \\(int\\|null\\) does not accept mixed\\.$#"
550550
count: 1
551551
path: src/Statements/ExplainStatement.php
552552

@@ -590,11 +590,6 @@ parameters:
590590
count: 1
591591
path: src/Statements/MaintenanceStatement.php
592592

593-
-
594-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\PurgeStatement\\:\\:\\$endExpr \\(string\\|null\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null\\.$#"
595-
count: 1
596-
path: src/Statements/PurgeStatement.php
597-
598593
-
599594
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\PurgeStatement\\:\\:\\$endOption \\(string\\|null\\) does not accept mixed\\.$#"
600595
count: 1

psalm-baseline.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,6 @@
770770
)]]></code>
771771
<code>ArrayObj::parse($parser, $list)</code>
772772
</PropertyTypeCoercion>
773-
<RedundantConditionGivenDocblockType>
774-
<code><![CDATA[$this->fields instanceof ArrayObj]]></code>
775-
</RedundantConditionGivenDocblockType>
776773
</file>
777774
<file src="src/Statements/DeleteStatement.php">
778775
<MixedArgument>
@@ -811,7 +808,6 @@
811808
<file src="src/Statements/ExplainStatement.php">
812809
<MixedAssignment>
813810
<code><![CDATA[$this->connectionId]]></code>
814-
<code><![CDATA[$this->explainedColumn]]></code>
815811
<code><![CDATA[$this->explainedDatabase]]></code>
816812
<code><![CDATA[$this->explainedTable]]></code>
817813
</MixedAssignment>
@@ -866,9 +862,6 @@
866862
</PossiblyUnusedProperty>
867863
</file>
868864
<file src="src/Statements/PurgeStatement.php">
869-
<ImplicitToStringCast>
870-
<code>Expression::parse($parser, $list, [])</code>
871-
</ImplicitToStringCast>
872865
<MixedAssignment>
873866
<code><![CDATA[$this->endOption]]></code>
874867
<code><![CDATA[$this->logType]]></code>

src/Statement.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class Statement implements Stringable
4545
* @var array<string, int|array<int, int|string>>
4646
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
4747
*/
48-
public static $statementOptions = [];
48+
public static array $statementOptions = [];
4949

5050
/**
5151
* The clauses of this statement, in order.
@@ -60,30 +60,24 @@ abstract class Statement implements Stringable
6060
* @var array<string, array<int, int|string>>
6161
* @psalm-var array<string, array{non-empty-string, (1|2|3)}>
6262
*/
63-
public static $clauses = [];
63+
public static array $clauses = [];
6464

6565
/**
6666
* The options of this query.
6767
*
6868
* @see Statement::$statementOptions
69-
*
70-
* @var OptionsArray|null
7169
*/
72-
public $options;
70+
public OptionsArray|null $options = null;
7371

7472
/**
7573
* The index of the first token used in this statement.
76-
*
77-
* @var int|null
7874
*/
79-
public $first;
75+
public int|null $first = null;
8076

8177
/**
8278
* The index of the last token used in this statement.
83-
*
84-
* @var int|null
8579
*/
86-
public $last;
80+
public int|null $last = null;
8781

8882
/**
8983
* @param Parser|null $parser the instance that requests parsing

src/Statements/AlterStatement.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,23 @@ class AlterStatement extends Statement
2222
{
2323
/**
2424
* Table affected.
25-
*
26-
* @var Expression|null
2725
*/
28-
public $table;
26+
public Expression|null $table = null;
2927

3028
/**
3129
* Column affected by this statement.
3230
*
3331
* @var AlterOperation[]|null
3432
*/
35-
public $altered = [];
33+
public array|null $altered = [];
3634

3735
/**
3836
* Options of this statement.
3937
*
4038
* @var array<string, int|array<int, int|string>>
4139
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
4240
*/
43-
public static $statementOptions = [
41+
public static array $statementOptions = [
4442
'ONLINE' => 1,
4543
'OFFLINE' => 1,
4644
'IGNORE' => 2,

src/Statements/AnalyzeStatement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AnalyzeStatement extends Statement
2121
* @var array<string, int|array<int, int|string>>
2222
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
2323
*/
24-
public static $statementOptions = [
24+
public static array $statementOptions = [
2525
'TABLE' => 1,
2626

2727
'NO_WRITE_TO_BINLOG' => 2,
@@ -33,5 +33,5 @@ class AnalyzeStatement extends Statement
3333
*
3434
* @var Expression[]|null
3535
*/
36-
public $tables;
36+
public array|null $tables = null;
3737
}

src/Statements/BackupStatement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BackupStatement extends MaintenanceStatement
1717
* @var array<string, int|array<int, int|string>>
1818
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
1919
*/
20-
public static $statementOptions = [
20+
public static array $statementOptions = [
2121
'TABLE' => 1,
2222

2323
'NO_WRITE_TO_BINLOG' => 2,

src/Statements/CallStatement.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ class CallStatement extends Statement
2222
{
2323
/**
2424
* The name of the function and its parameters.
25-
*
26-
* @var FunctionCall|null
2725
*/
28-
public $call;
26+
public FunctionCall|null $call = null;
2927

3028
/**
3129
* Build statement for CALL.

src/Statements/CheckStatement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CheckStatement extends MaintenanceStatement
1717
* @var array<string, int|array<int, int|string>>
1818
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
1919
*/
20-
public static $statementOptions = [
20+
public static array $statementOptions = [
2121
'TABLE' => 1,
2222

2323
'FOR UPGRADE' => 2,

src/Statements/ChecksumStatement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ChecksumStatement extends MaintenanceStatement
1717
* @var array<string, int|array<int, int|string>>
1818
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
1919
*/
20-
public static $statementOptions = [
20+
public static array $statementOptions = [
2121
'TABLE' => 1,
2222

2323
'QUICK' => 2,

src/Statements/CreateStatement.php

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CreateStatement extends Statement
3131
* @var array<string, int|array<int, int|string>>
3232
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
3333
*/
34-
public static $statementOptions = [
34+
public static array $statementOptions = [
3535
// CREATE TABLE
3636
'TEMPORARY' => 1,
3737

@@ -279,10 +279,8 @@ class CreateStatement extends Statement
279279
* @see CreateStatement::TABLE_OPTIONS
280280
* @see CreateStatement::FUNCTION_OPTIONS
281281
* @see CreateStatement::TRIGGER_OPTIONS
282-
*
283-
* @var OptionsArray|null
284282
*/
285-
public $entityOptions;
283+
public OptionsArray|null $entityOptions = null;
286284

287285
/**
288286
* If `CREATE TABLE`, a list of columns and keys.
@@ -292,90 +290,72 @@ class CreateStatement extends Statement
292290
*
293291
* @var CreateDefinition[]|ArrayObj|null
294292
*/
295-
public $fields;
293+
public array|ArrayObj|null $fields = null;
296294

297295
/**
298296
* If `CREATE TABLE WITH`.
299297
* If `CREATE TABLE AS WITH`.
300298
* If `CREATE VIEW AS WITH`.
301299
*
302300
* Used by `CREATE TABLE`, `CREATE VIEW`
303-
*
304-
* @var WithStatement|null
305301
*/
306-
public $with;
302+
public WithStatement|null $with = null;
307303

308304
/**
309305
* If `CREATE TABLE ... SELECT`.
310306
* If `CREATE VIEW AS ` ... SELECT`.
311307
*
312308
* Used by `CREATE TABLE`, `CREATE VIEW`
313-
*
314-
* @var SelectStatement|null
315309
*/
316-
public $select;
310+
public SelectStatement|null $select = null;
317311

318312
/**
319313
* If `CREATE TABLE ... LIKE`.
320314
*
321315
* Used by `CREATE TABLE`
322-
*
323-
* @var Expression|null
324316
*/
325-
public $like;
317+
public Expression|null $like = null;
326318

327319
/**
328320
* Expression used for partitioning.
329-
*
330-
* @var string|null
331321
*/
332-
public $partitionBy;
322+
public string|null $partitionBy = null;
333323

334324
/**
335325
* The number of partitions.
336-
*
337-
* @var int|null
338326
*/
339-
public $partitionsNum;
327+
public int|null $partitionsNum = null;
340328

341329
/**
342330
* Expression used for subpartitioning.
343-
*
344-
* @var string|null
345331
*/
346-
public $subpartitionBy;
332+
public string|null $subpartitionBy = null;
347333

348334
/**
349335
* The number of subpartitions.
350-
*
351-
* @var int|null
352336
*/
353-
public $subpartitionsNum;
337+
public int|null $subpartitionsNum = null;
354338

355339
/**
356340
* The partition of the new table.
357341
*
358342
* @var PartitionDefinition[]|null
359343
*/
360-
public $partitions;
344+
public array|null $partitions = null;
361345

362346
/**
363347
* If `CREATE TRIGGER` the name of the table.
364348
*
365349
* Used by `CREATE TRIGGER`.
366-
*
367-
* @var Expression|null
368350
*/
369-
public $table;
351+
public Expression|null $table = null;
370352

371353
/**
372354
* The return data type of this routine.
373355
*
374356
* Used by `CREATE FUNCTION`.
375-
*
376-
* @var DataType|null
377357
*/
378-
public $return;
358+
public DataType|null $return = null;
379359

380360
/**
381361
* The parameters of this routine.
@@ -384,7 +364,7 @@ class CreateStatement extends Statement
384364
*
385365
* @var ParameterDefinition[]|null
386366
*/
387-
public $parameters;
367+
public array|null $parameters = null;
388368

389369
/**
390370
* The body of this function or procedure.
@@ -398,10 +378,10 @@ class CreateStatement extends Statement
398378
public function build(): string
399379
{
400380
$fields = '';
401-
if (! empty($this->fields)) {
381+
if ($this->fields !== null && $this->fields !== []) {
402382
if (is_array($this->fields)) {
403383
$fields = CreateDefinition::buildAll($this->fields) . ' ';
404-
} elseif ($this->fields instanceof ArrayObj) {
384+
} else {
405385
$fields = $this->fields->build();
406386
}
407387
}
@@ -589,7 +569,7 @@ public function parse(Parser $parser, TokensList $list): void
589569
}
590570
} else {
591571
$this->fields = CreateDefinition::parse($parser, $list);
592-
if (empty($this->fields)) {
572+
if ($this->fields === []) {
593573
$parser->error('At least one column definition was expected.', $list->tokens[$list->idx]);
594574
}
595575

0 commit comments

Comments
 (0)