Completed
Push — master ( 391062...ff47c5 )
by Rasmus
02:37
created

DeleteQuery::buildQuery()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.0113

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 12
cts 13
cp 0.9231
rs 8.8571
cc 5
eloc 13
nc 16
nop 0
crap 5.0113
1
<?php
2
3
namespace mindplay\sql\model;
4
5
use mindplay\sql\framework\Driver;
6
use mindplay\sql\framework\TypeProvider;
7
8
/**
9
 * This class represents a DELETE query.
10
 */
11
class DeleteQuery extends ProjectionQuery
12
{
13 1
    public function getSQL()
14
    {
15 1
        $delete = "DELETE FROM " . $this->buildNodes();
16
17 1
        $where = count($this->conditions)
18 1
            ? "\nWHERE " . $this->buildConditions()
19 1
            : ''; // no conditions present
20
21 1
        $order = count($this->order)
22
            ? "\nORDER BY " . $this->buildOrderTerms()
23 1
            : ''; // no order terms
24
25 1
        $limit = $this->limit !== null
26 1
            ? "\nLIMIT {$this->limit}"
27 1
            . ($this->offset !== null ? " OFFSET {$this->offset}" : '')
28 1
            : ''; // no limit or offset
29
30 1
        return "{$delete}{$where}{$order}{$limit}";
31
    }
32
}
33