Total Complexity | 5 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class Truncate implements ITruncate |
||
11 | { |
||
12 | /** @var array<int,Table|string> */ |
||
13 | protected array $tables = []; |
||
14 | |||
15 | /** |
||
16 | * @param Table|string ...$tables |
||
17 | * |
||
18 | * @return $this |
||
19 | */ |
||
20 | 6 | public function from(Table|string ...$tables): static |
|
21 | { |
||
22 | 6 | $this->tables = array_merge($this->tables, $tables); |
|
23 | |||
24 | 6 | return $this; |
|
25 | } |
||
26 | |||
27 | /** |
||
28 | * @return string |
||
29 | */ |
||
30 | 5 | public function __toString(): string |
|
31 | { |
||
32 | 5 | if (!$this->isValid()) { |
|
33 | 1 | throw new RuntimeException('under-initialized TRUNCATE query'); |
|
34 | } |
||
35 | |||
36 | 4 | return 'TRUNCATE ' . implode(', ', $this->tables); |
|
37 | } |
||
38 | |||
39 | 5 | public function isValid(): bool |
|
40 | { |
||
41 | 5 | return count($this->tables) > 0; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return array |
||
46 | */ |
||
47 | 1 | public function getParams(): array |
|
50 | } |
||
51 | } |
||
52 |