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

SelectQuery::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace mindplay\sql\model;
4
5
/**
6
 * This class represents a SELECT query.
7
 *
8
 * This class implements `__toString()` magic, enabling the use of this query builder
9
 * in the SELECT, WHERE or ORDER BY clause of a parent SELECT (or other type of) query.
10
 *
11
 * Note that, when constructing nested queries, parameters must be bound against the
12
 * parent query - binding parameters or applying Mappers against a nested query has no effect.
13
 */
14
class SelectQuery extends ReturningQuery
15
{
16
    /**
17
     * @inheritdoc
18
     */
19 1 View Code Duplication
    public function getSQL()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21 1
        $select = "SELECT " . $this->buildReturnVars();
22
23 1
        $from = "\nFROM " . $this->buildNodes();
24
25 1
        $where = count($this->conditions)
26 1
            ? "\nWHERE " . $this->buildConditions()
27 1
            : ''; // no conditions present
28
29 1
        $order = count($this->order)
30 1
            ? "\nORDER BY " . $this->buildOrderTerms()
31 1
            : ''; // no order terms
32
33 1
        $limit = $this->limit !== null
34 1
            ? "\nLIMIT {$this->limit}"
35 1
            . ($this->offset !== null ? " OFFSET {$this->offset}" : '')
36 1
            : ''; // no limit or offset
37
38 1
        return "{$select}{$from}{$where}{$order}{$limit}";
39
    }
40
41
    /**
42
     * @ignore string magic (enables creation of nested SELECT queries)
43
     */
44 1
    public function __toString()
45
    {
46 1
        return "(" . $this->getSQL() . ")";
47
    }
48
}
49