1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace PhpMyAdmin\SqlParser\Components; |
||
6 | |||
7 | use PhpMyAdmin\SqlParser\Component; |
||
8 | use PhpMyAdmin\SqlParser\Parser; |
||
9 | use PhpMyAdmin\SqlParser\Parsers\ArrayObjs; |
||
10 | use RuntimeException; |
||
11 | |||
12 | /** |
||
13 | * `WITH` keyword builder. |
||
14 | */ |
||
15 | final class WithKeyword implements Component |
||
16 | { |
||
17 | /** @var ArrayObj[] */ |
||
18 | public array $columns = []; |
||
19 | |||
20 | public Parser|null $statement = null; |
||
21 | |||
22 | 50 | public function __construct(public string $name) |
|
23 | { |
||
24 | 50 | } |
|
25 | |||
26 | 12 | public function build(): string |
|
27 | { |
||
28 | 12 | if (! isset($this->statement)) { |
|
29 | 2 | throw new RuntimeException('No statement inside WITH'); |
|
30 | } |
||
31 | |||
32 | 10 | $str = $this->name; |
|
33 | |||
34 | 10 | if ($this->columns) { |
|
0 ignored issues
–
show
|
|||
35 | 6 | $str .= ArrayObjs::buildAll($this->columns); |
|
36 | } |
||
37 | |||
38 | 10 | $str .= ' AS ('; |
|
39 | |||
40 | 10 | foreach ($this->statement->statements as $statement) { |
|
41 | 10 | $str .= $statement->build(); |
|
42 | } |
||
43 | |||
44 | 10 | $str .= ')'; |
|
45 | |||
46 | 10 | return $str; |
|
47 | } |
||
48 | |||
49 | public function __toString(): string |
||
50 | { |
||
51 | return $this->build(); |
||
52 | } |
||
53 | } |
||
54 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.