Completed
Push — master ( 509987...79a3d2 )
by Rasmus
02:45
created

DeleteQuery::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
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
3
namespace mindplay\sql\model\query;
4
5
use mindplay\sql\model\components\Conditions;
6
use mindplay\sql\model\schema\Table;
7
use mindplay\sql\model\TypeProvider;
8
9
/**
10
 * This class represents a DELETE query.
11
 */
12
class DeleteQuery extends Query
13
{
14
    use Conditions;
15
16
    /**
17
     * @var Table Table from which to DELETE
18
     */
19
    protected $table;
20
21
    /**
22
     * @param Table        $table
23
     * @param TypeProvider $types
24
     */
25 1
    public function __construct(Table $table, TypeProvider $types)
26
    {
27 1
        parent::__construct($types);
28
29 1
        $this->table = $table;
30 1
    }
31
32 1
    public function getSQL()
33
    {
34 1
        $delete = "DELETE FROM " . $this->table->getNode();
35
36 1
        $where = count($this->conditions)
37 1
            ? "\nWHERE " . $this->buildConditions()
38 1
            : ''; // no conditions present
39
40 1
        return "{$delete}{$where}";
41
    }
42
}
43