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

SelectQuery   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 60 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 21
loc 35
wmc 6
lcom 1
cbo 1
ccs 16
cts 16
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
B getSQL() 21 21 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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