DeleteQuery   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 26
ccs 8
cts 9
cp 0.8889
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSQL() 0 9 2
A __construct() 0 5 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
    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