Completed
Push — master ( f707f5...a08928 )
by Rasmus
02:27
created

DeleteQuery::getSQL()   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\query;
4
5
/**
6
 * This class represents a DELETE query.
7
 */
8
class DeleteQuery extends ProjectionQuery
9
{
10 1
    public function getSQL()
11
    {
12 1
        $delete = "DELETE FROM " . $this->buildNodes();
13
14 1
        $where = count($this->conditions)
15 1
            ? "\nWHERE " . $this->buildConditions()
16 1
            : ''; // no conditions present
17
18 1
        $order = count($this->order)
19
            ? "\nORDER BY " . $this->buildOrderTerms()
20 1
            : ''; // no order terms
21
22 1
        $limit = $this->limit !== null
23 1
            ? "\nLIMIT {$this->limit}"
24 1
            . ($this->offset !== null ? " OFFSET {$this->offset}" : '')
25 1
            : ''; // no limit or offset
26
27 1
        return "{$delete}{$where}{$order}{$limit}";
28
    }
29
}
30