Skip to content

Commit 7980970

Browse files
Merge pull request #463 from kamil-tekiela/Set-types-from-count
Set native types from count
2 parents 539462d + 9faa4c3 commit 7980970

14 files changed

+37
-53
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,6 @@ parameters:
580580
count: 1
581581
path: src/Statement.php
582582

583-
-
584-
message: "#^Strict comparison using \\=\\=\\= between int\\<1, max\\> and 0 will always evaluate to false\\.$#"
585-
count: 1
586-
path: src/Statement.php
587-
588583
-
589584
message: "#^Argument of an invalid type array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\AlterOperation\\>\\|null supplied for foreach, only iterables are supported\\.$#"
590585
count: 1

psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -977,9 +977,6 @@
977977
<RedundantConditionGivenDocblockType>
978978
<code>$class !== null</code>
979979
</RedundantConditionGivenDocblockType>
980-
<TypeDoesNotContainType>
981-
<code>count($clauses) === 0</code>
982-
</TypeDoesNotContainType>
983980
<UndefinedAttributeClass>
984981
<code>\AllowDynamicProperties</code>
985982
</UndefinedAttributeClass>

src/Components/OptionsArray.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class OptionsArray implements Component
2929
*
3030
* @var array<int, mixed>
3131
*/
32-
public $options = [];
32+
public array $options = [];
3333

3434
/**
3535
* @param array<int, mixed> $options The array of options. Options that have a value

src/Core.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Core
3131
*
3232
* @var Exception[]
3333
*/
34-
public $errors = [];
34+
public array $errors = [];
3535

3636
public function __construct()
3737
{

src/Statement.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use function array_flip;
1111
use function array_keys;
12-
use function count;
1312
use function in_array;
1413
use function stripos;
1514
use function trim;
@@ -443,7 +442,7 @@ public function after(Parser $parser, TokensList $list, Token $token): void
443442
* @return array<string, array<int, int|string>>
444443
* @psalm-return array<string, array{non-empty-string, (1|2|3)}>
445444
*/
446-
public function getClauses()
445+
public function getClauses(): array
447446
{
448447
return static::$clauses;
449448
}
@@ -476,7 +475,7 @@ public function validateClauseOrder($parser, $list)
476475
{
477476
$clauses = array_flip(array_keys($this->getClauses()));
478477

479-
if (empty($clauses) || count($clauses) === 0) {
478+
if ($clauses === []) {
480479
return true;
481480
}
482481

src/Statements/DeleteStatement.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use PhpMyAdmin\SqlParser\Token;
1818
use PhpMyAdmin\SqlParser\TokensList;
1919

20-
use function count;
2120
use function stripos;
2221
use function strlen;
2322

@@ -107,28 +106,28 @@ class DeleteStatement extends Statement
107106
*
108107
* @var Expression[]|null
109108
*/
110-
public $from;
109+
public array|null $from = null;
111110

112111
/**
113112
* Joins.
114113
*
115114
* @var JoinKeyword[]|null
116115
*/
117-
public $join;
116+
public array|null $join = null;
118117

119118
/**
120119
* Tables used as sources for this statement.
121120
*
122121
* @var Expression[]|null
123122
*/
124-
public $using;
123+
public array|null $using = null;
125124

126125
/**
127126
* Columns used in this statement.
128127
*
129128
* @var Expression[]|null
130129
*/
131-
public $columns;
130+
public array|null $columns = null;
132131

133132
/**
134133
* Partitions used as source for this statement.
@@ -142,14 +141,14 @@ class DeleteStatement extends Statement
142141
*
143142
* @var Condition[]|null
144143
*/
145-
public $where;
144+
public array|null $where = null;
146145

147146
/**
148147
* Specifies the order of the rows in the result set.
149148
*
150149
* @var OrderKeyword[]|null
151150
*/
152-
public $order;
151+
public array|null $order = null;
153152

154153
/**
155154
* Conditions used for limiting the size of the result set.
@@ -165,27 +164,27 @@ public function build()
165164
{
166165
$ret = 'DELETE ' . OptionsArray::build($this->options);
167166

168-
if ($this->columns !== null && count($this->columns) > 0) {
167+
if ($this->columns !== null && $this->columns !== []) {
169168
$ret .= ' ' . ExpressionArray::build($this->columns);
170169
}
171170

172-
if ($this->from !== null && count($this->from) > 0) {
171+
if ($this->from !== null && $this->from !== []) {
173172
$ret .= ' FROM ' . ExpressionArray::build($this->from);
174173
}
175174

176-
if ($this->join !== null && count($this->join) > 0) {
175+
if ($this->join !== null && $this->join !== []) {
177176
$ret .= ' ' . JoinKeyword::build($this->join);
178177
}
179178

180-
if ($this->using !== null && count($this->using) > 0) {
179+
if ($this->using !== null && $this->using !== []) {
181180
$ret .= ' USING ' . ExpressionArray::build($this->using);
182181
}
183182

184-
if ($this->where !== null && count($this->where) > 0) {
183+
if ($this->where !== null && $this->where !== []) {
185184
$ret .= ' WHERE ' . Condition::build($this->where);
186185
}
187186

188-
if ($this->order !== null && count($this->order) > 0) {
187+
if ($this->order !== null && $this->order !== []) {
189188
$ret .= ' ORDER BY ' . ExpressionArray::build($this->order);
190189
}
191190

src/Statements/ExplainStatement.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use PhpMyAdmin\SqlParser\TokensList;
1313

1414
use function array_slice;
15-
use function count;
1615

1716
/**
1817
* `EXPLAIN` statement.
@@ -201,7 +200,7 @@ public function parse(Parser $parser, TokensList $list): void
201200
$subList = new TokensList(array_slice($list->tokens, $list->idx));
202201

203202
$this->bodyParser = new Parser($subList);
204-
if (count($this->bodyParser->errors)) {
203+
if ($this->bodyParser->errors !== []) {
205204
foreach ($this->bodyParser->errors as $error) {
206205
$parser->errors[] = $error;
207206
}
@@ -252,7 +251,7 @@ public function build(): string
252251
$str = $this->statementAlias;
253252

254253
if ($this->options !== null) {
255-
if (count($this->options->options)) {
254+
if ($this->options->options !== []) {
256255
$str .= ' ';
257256
}
258257

src/Statements/InsertStatement.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PhpMyAdmin\SqlParser\Token;
1515
use PhpMyAdmin\SqlParser\TokensList;
1616

17-
use function count;
1817
use function strlen;
1918
use function trim;
2019

@@ -78,15 +77,15 @@ class InsertStatement extends Statement
7877
*
7978
* @var ArrayObj[]|null
8079
*/
81-
public $values;
80+
public array|null $values = null;
8281

8382
/**
8483
* If SET clause is present
8584
* holds the SetOperation.
8685
*
8786
* @var SetOperation[]|null
8887
*/
89-
public $set;
88+
public array|null $set = null;
9089

9190
/**
9291
* If SELECT clause is present
@@ -110,7 +109,7 @@ class InsertStatement extends Statement
110109
*
111110
* @var SetOperation[]|null
112111
*/
113-
public $onDuplicateSet;
112+
public array|null $onDuplicateSet = null;
114113

115114
/**
116115
* @return string
@@ -120,15 +119,15 @@ public function build()
120119
$ret = 'INSERT ' . $this->options;
121120
$ret = trim($ret) . ' INTO ' . $this->into;
122121

123-
if ($this->values !== null && count($this->values) > 0) {
122+
if ($this->values !== null && $this->values !== []) {
124123
$ret .= ' VALUES ' . Array2d::build($this->values);
125-
} elseif ($this->set !== null && count($this->set) > 0) {
124+
} elseif ($this->set !== null && $this->set !== []) {
126125
$ret .= ' SET ' . SetOperation::build($this->set);
127126
} elseif ($this->select !== null && strlen((string) $this->select) > 0) {
128127
$ret .= ' ' . $this->select->build();
129128
}
130129

131-
if ($this->onDuplicateSet !== null && count($this->onDuplicateSet) > 0) {
130+
if ($this->onDuplicateSet !== null && $this->onDuplicateSet !== []) {
132131
$ret .= ' ON DUPLICATE KEY UPDATE ' . SetOperation::build($this->onDuplicateSet);
133132
}
134133

src/Statements/LoadStatement.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PhpMyAdmin\SqlParser\Token;
1515
use PhpMyAdmin\SqlParser\TokensList;
1616

17-
use function count;
1817
use function strlen;
1918
use function trim;
2019

@@ -150,14 +149,14 @@ class LoadStatement extends Statement
150149
*
151150
* @var Expression[]|null
152151
*/
153-
public $columnNamesOrUserVariables;
152+
public array|null $columnNamesOrUserVariables = null;
154153

155154
/**
156155
* SET clause's updated values(optional).
157156
*
158157
* @var SetOperation[]|null
159158
*/
160-
public $set;
159+
public array|null $set = null;
161160

162161
/**
163162
* Ignore 'number' LINES/ROWS.
@@ -214,11 +213,11 @@ public function build()
214213
$ret .= ' IGNORE ' . $this->ignoreNumber . ' ' . $this->linesRows;
215214
}
216215

217-
if ($this->columnNamesOrUserVariables !== null && count($this->columnNamesOrUserVariables) > 0) {
216+
if ($this->columnNamesOrUserVariables !== null && $this->columnNamesOrUserVariables !== []) {
218217
$ret .= ' ' . ExpressionArray::build($this->columnNamesOrUserVariables);
219218
}
220219

221-
if ($this->set !== null && count($this->set) > 0) {
220+
if ($this->set !== null && $this->set !== []) {
222221
$ret .= ' SET ' . SetOperation::build($this->set);
223222
}
224223

src/Statements/ReplaceStatement.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use PhpMyAdmin\SqlParser\Token;
1414
use PhpMyAdmin\SqlParser\TokensList;
1515

16-
use function count;
1716
use function strlen;
1817
use function trim;
1918

@@ -71,7 +70,7 @@ class ReplaceStatement extends Statement
7170
*
7271
* @var SetOperation[]|null
7372
*/
74-
public $set;
73+
public array|null $set = null;
7574

7675
/**
7776
* If SELECT clause is present
@@ -89,9 +88,9 @@ public function build()
8988
$ret = 'REPLACE ' . $this->options;
9089
$ret = trim($ret) . ' INTO ' . $this->into;
9190

92-
if ($this->values !== null && count($this->values) > 0) {
91+
if ($this->values !== null && $this->values !== []) {
9392
$ret .= ' VALUES ' . Array2d::build($this->values);
94-
} elseif ($this->set !== null && count($this->set) > 0) {
93+
} elseif ($this->set !== null && $this->set !== []) {
9594
$ret .= ' SET ' . SetOperation::build($this->set);
9695
} elseif ($this->select !== null && strlen((string) $this->select) > 0) {
9796
$ret .= ' ' . $this->select->build();

0 commit comments

Comments
 (0)