Passed
Push — main ( 303b6c...b49db2 )
by Sammy
01:47 queued 15s
created

Delete   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A bindings() 0 3 1
A __construct() 0 8 2
A statement() 0 3 1
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
    protected $table;
10
    
11
12
    public function __construct(string $table, array $strict_conditions)
13
    {
14
        if (empty($strict_conditions)) {
15
            throw new \InvalidArgumentException('DELETE_USED_AS_TRUNCATE');
16
        }
17
18
        $this->table = $table;
19
        $this->add((new Where($table))->andFields($strict_conditions, $table, '='));
20
    }
21
22
    public function statement(): string
23
    {
24
        return sprintf('DELETE FROM `%s` %s ', $this->table, $this->clause(Where::WHERE));
25
    }
26
27
    public function bindings(): array
28
    {
29
        return $this->clause(Where::WHERE)->bindings();
30
    }
31
}
32