Completed
Push — master ( b6a1f4...39b084 )
by Jared
02:16
created

DeleteQuery::orderBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
/**
4
 * @author Jared King <[email protected]>
5
 *
6
 * @link http://jaredtking.com
7
 *
8
 * @copyright 2015 Jared King
9
 * @license MIT
10
 */
11
namespace JAQB\Query;
12
13
use JAQB\Operations\Executable;
14
use JAQB\Statement\FromStatement;
15
use JAQB\Statement\LimitStatement;
16
use JAQB\Statement\OrderStatement;
17
use JAQB\Statement\WhereStatement;
18
use JAQB\Query\Traits\OrderBy;
19
use JAQB\Query\Traits\WhereConditions;
20
21
class DeleteQuery extends AbstractQuery
22
{
23
    use Executable, OrderBy, WhereConditions;
24
25
    /**
26
     * @var FromStatement
27
     */
28
    protected $from;
29
30
    /**
31
     * @var LimitStatement
32
     */
33
    protected $limit;
34
35 View Code Duplication
    public function __construct()
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...
36
    {
37
        $this->from = new FromStatement(FromStatement::DELETE);
38
        $this->where = new WhereStatement();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \JAQB\Statement\WhereStatement() of type object<JAQB\Statement\WhereStatement> is incompatible with the declared type object<JAQB\Query\Traits\WhereStatement> of property $where.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
39
        $this->orderBy = new OrderStatement();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \JAQB\Statement\OrderStatement() of type object<JAQB\Statement\OrderStatement> is incompatible with the declared type object<JAQB\Query\Traits\OrderStatement> of property $orderBy.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
        $this->limit = new LimitStatement();
41
    }
42
43
    /**
44
     * Sets the table for the query.
45
     *
46
     * @param string $table table name
47
     *
48
     * @return self
49
     */
50
    public function from($table)
51
    {
52
        $this->from->addTable($table);
53
54
        return $this;
55
    }
56
57
    /**
58
     * Sets the limit for the query.
59
     *
60
     * @param int $limit
61
     * @param int $offset
62
     *
63
     * @return self
64
     */
65
    public function limit($limit, $offset = 0)
66
    {
67
        $this->limit->setLimit($limit, $offset);
68
69
        return $this;
70
    }
71
72
    /**
73
     * Gets the from statement for the query.
74
     *
75
     * @return FromStatement
76
     */
77
    public function getFrom()
78
    {
79
        return $this->from;
80
    }
81
82
    /**
83
     * Gets the limit statement for the query.
84
     *
85
     * @return LimitStatement
86
     */
87
    public function getLimit()
88
    {
89
        return $this->limit;
90
    }
91
92
    /**
93
     * Generates the raw SQL string for the query.
94
     *
95
     * @return string
96
     */
97
    public function build()
98
    {
99
        $sql = [
100
            $this->from->build(),
101
            $this->where->build(),
102
            $this->orderBy->build(),
103
            $this->limit->build(),
104
        ];
105
106
        $this->values = $this->where->getValues();
107
108
        return implode(' ', array_filter($sql));
109
    }
110
111
    public function __clone()
112
    {
113
        $this->from = clone $this->from;
114
        $this->where = clone $this->where;
115
        $this->orderBy = clone $this->orderBy;
116
        $this->limit = clone $this->limit;
117
    }
118
}
119