Truncate   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 40
rs 10
c 1
b 0
f 0
ccs 11
cts 11
cp 1
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getParams() 0 3 1
A __toString() 0 7 2
A from() 0 5 1
A isValid() 0 3 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