Passed
Push — main ( 440f49...00eeb9 )
by Peter
02:41
created

Truncate::addFrom()   A

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\Generic\Statement;
6
7
use QB\Generic\Clause\Table;
8
9
class Truncate implements ITruncate
10
{
11
    /** @var array<int,string|Table> */
12
    protected array $tables = [];
13
14
    /**
15
     * @param string|Table ...$tables
16
     *
17
     * @return $this
18
     */
19 6
    public function from(string|Table ...$tables): static
20
    {
21 6
        $this->tables = array_merge($this->tables, $tables);
22
23 6
        return $this;
24
    }
25
26
    /**
27
     * @return string
28
     */
29 5
    public function __toString(): string
30
    {
31 5
        if (!$this->isValid()) {
32 1
            throw new \RuntimeException('under-initialized TRUNCATE query');
33
        }
34
35 4
        return 'TRUNCATE ' . implode(', ', $this->tables);
36
    }
37
38 5
    public function isValid(): bool
39
    {
40 5
        return count($this->tables) > 0;
41
    }
42
43
    /**
44
     * @return array
45
     */
46 1
    public function getParams(): array
47
    {
48 1
        return [];
49
    }
50
}
51