Total Complexity | 6 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Coverage | 86.67% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | final class WithKeyword implements Component |
||
15 | { |
||
16 | /** @var string */ |
||
17 | public $name; |
||
18 | |||
19 | /** @var ArrayObj[] */ |
||
20 | public $columns = []; |
||
21 | |||
22 | /** @var Parser|null */ |
||
23 | public $statement; |
||
24 | |||
25 | 50 | public function __construct(string $name) |
|
28 | } |
||
29 | |||
30 | 12 | public function build(): string |
|
31 | { |
||
32 | 12 | if (! isset($this->statement)) { |
|
33 | 2 | throw new RuntimeException('No statement inside WITH'); |
|
34 | } |
||
35 | |||
36 | 10 | $str = $this->name; |
|
37 | |||
38 | 10 | if ($this->columns) { |
|
|
|||
39 | 6 | $str .= ArrayObj::buildAll($this->columns); |
|
40 | } |
||
41 | |||
42 | 10 | $str .= ' AS ('; |
|
43 | |||
44 | 10 | foreach ($this->statement->statements as $statement) { |
|
45 | 10 | $str .= $statement->build(); |
|
46 | } |
||
47 | |||
48 | 10 | $str .= ')'; |
|
49 | |||
50 | 10 | return $str; |
|
51 | } |
||
52 | |||
53 | public function __toString(): string |
||
56 | } |
||
57 | } |
||
58 |
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.