Delete::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace HexMakina\Crudites\Grammar\Query;
4
5
use HexMakina\Crudites\Grammar\Clause\Where;
6
7
class Delete extends Query
8
{
9
    public function __construct(string $table, array $strict_conditions)
10
    {
11
        if (empty($strict_conditions)) {
12
            throw new \InvalidArgumentException('DELETE_USED_AS_TRUNCATE');
13
        }
14
15
        $this->table = $table;
16
        $this->add((new Where())->andFields($strict_conditions, $table, '='));
17
    }
18
19
    public function statement(): string
20
    {
21
        return sprintf('DELETE FROM `%s` %s ', $this->table, $this->clause(Where::WHERE));
22
    }
23
24
    public function bindings(): array
25
    {
26
        return $this->clause(Where::WHERE)->bindings();
27
    }
28
}
29