DeleteQuery::getSQL()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
crap 2.0185
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