Truncate::__toString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 1
b 0
f 0
ccs 4
cts 4
cp 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\Generic\Statement;
6
7
use QB\Generic\Clause\Table;
8
use RuntimeException;
9
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
48
    {
49 1
        return [];
50
    }
51
}
52