DeleteQuery::__construct()   A
last analyzed

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 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
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
    protected Table $table;
17
18
    /**
19
     * @param $table Table from which to DELETE
20
     * @param $types
21
     */
22 1
    public function __construct(Table $table, TypeProvider $types)
23
    {
24 1
        parent::__construct($types);
25
26 1
        $this->table = $table;
27
    }
28
29 1
    public function getSQL(): string
30
    {
31 1
        $delete = "DELETE FROM " . $this->table->getNode();
32
33 1
        $where = count($this->conditions)
34 1
            ? "\nWHERE " . $this->buildConditions()
35
            : ''; // no conditions present
36
37 1
        return "{$delete}{$where}";
38
    }
39
}
40