ModifyColumns::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Sql\Component;
5
6
use Sirius\Sql\Bindings;
7
use Sirius\Sql\Quoter\Quoter;
8
use Sirius\Sql\Raw;
9
10
abstract class ModifyColumns extends Component
11
{
12
    protected $bindings;
13
14
    protected $list = [];
15
16
    protected $quoter;
17
18 2
    public function __construct(Bindings $bindings, Quoter $quoter)
19
    {
20 2
        $this->bindings = $bindings;
21 2
        $this->quoter   = $quoter;
22 2
    }
23
24 2
    public function hasAny(): bool
25
    {
26 2
        return ! empty($this->list);
27
    }
28
29 2
    public function hold(string $column, ...$value): void
30
    {
31 2
        if (! empty($value) && $value[0] instanceof Raw) {
32 1
            $this->list[$column] = (string)$value[0];
33
34 1
            return;
35
        }
36
37 2
        $this->list[$column] = ":{$column}";
38 2
        if (! empty($value)) {
39 2
            $this->bindings->value($column, ...$value);
40
        }
41 2
    }
42
}
43