Completed
Push — master ( ffb751...b6a1f4 )
by Jared
02:13
created

DeleteQuery::notBetween()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
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\WhereConditions;
19
20
class DeleteQuery extends AbstractQuery
21
{
22
    use Executable, WhereConditions;
23
24
    /**
25
     * @var FromStatement
26
     */
27
    protected $from;
28
29
    /**
30
     * @var OrderStatement
31
     */
32
    protected $orderBy;
33
34
    /**
35
     * @var LimitStatement
36
     */
37
    protected $limit;
38
39 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...
40
    {
41
        $this->from = new FromStatement(FromStatement::DELETE);
42
        $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...
43
        $this->orderBy = new OrderStatement();
44
        $this->limit = new LimitStatement();
45
    }
46
47
    /**
48
     * Sets the table for the query.
49
     *
50
     * @param string $table table name
51
     *
52
     * @return self
53
     */
54
    public function from($table)
55
    {
56
        $this->from->addTable($table);
57
58
        return $this;
59
    }
60
61
    /**
62
     * Sets the limit for the query.
63
     *
64
     * @param int $limit
65
     * @param int $offset
66
     *
67
     * @return self
68
     */
69
    public function limit($limit, $offset = 0)
70
    {
71
        $this->limit->setLimit($limit, $offset);
72
73
        return $this;
74
    }
75
76
    /**
77
     * Sets the order for the query.
78
     *
79
     * @param string|array $fields
80
     * @param string       $direction
81
     *
82
     * @return self
83
     */
84
    public function orderBy($fields, $direction = false)
85
    {
86
        $this->orderBy->addFields($fields, $direction);
87
88
        return $this;
89
    }
90
91
    /**
92
     * Gets the from statement for the query.
93
     *
94
     * @return FromStatement
95
     */
96
    public function getFrom()
97
    {
98
        return $this->from;
99
    }
100
101
    /**
102
     * Gets the limit statement for the query.
103
     *
104
     * @return LimitStatement
105
     */
106
    public function getLimit()
107
    {
108
        return $this->limit;
109
    }
110
111
    /**
112
     * Gets the order by statement for the query.
113
     *
114
     * @return OrderByStatement
115
     */
116
    public function getOrderBy()
117
    {
118
        return $this->orderBy;
119
    }
120
121
    /**
122
     * Generates the raw SQL string for the query.
123
     *
124
     * @return string
125
     */
126
    public function build()
127
    {
128
        $sql = [
129
            $this->from->build(),
130
            $this->where->build(),
131
            $this->orderBy->build(),
132
            $this->limit->build(),
133
        ];
134
135
        $this->values = $this->where->getValues();
136
137
        return implode(' ', array_filter($sql));
138
    }
139
140
    public function __clone()
141
    {
142
        $this->from = clone $this->from;
143
        $this->where = clone $this->where;
144
        $this->orderBy = clone $this->orderBy;
145
        $this->limit = clone $this->limit;
146
    }
147
}
148