Truncate::from()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
ccs 3
cts 3
cp 1
crap 1
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