Completed
Push — master ( 860e6f...c234e1 )
by Jared
02:12
created

DeleteQuery::getLimit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Limit;
19
use JAQB\Query\Traits\OrderBy;
20
use JAQB\Query\Traits\Where;
21
22
class DeleteQuery extends AbstractQuery
23
{
24
    use Executable, Limit, OrderBy, Where;
25
26
    /**
27
     * @var FromStatement
28
     */
29
    protected $from;
30
31 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...
32
    {
33
        $this->from = new FromStatement(FromStatement::DELETE);
34
        $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...atement\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...
35
        $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...atement\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...
36
        $this->limit = new LimitStatement();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \JAQB\Statement\LimitStatement() of type object<JAQB\Statement\LimitStatement> is incompatible with the declared type object<JAQB\Query\Traits...atement\LimitStatement> of property $limit.

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...
37
    }
38
39
    /**
40
     * Sets the table for the query.
41
     *
42
     * @param string $table table name
43
     *
44
     * @return self
45
     */
46
    public function from($table)
47
    {
48
        $this->from->addTable($table);
49
50
        return $this;
51
    }
52
53
    /**
54
     * Gets the from statement for the query.
55
     *
56
     * @return FromStatement
57
     */
58
    public function getFrom()
59
    {
60
        return $this->from;
61
    }
62
63
    /**
64
     * Generates the raw SQL string for the query.
65
     *
66
     * @return string
67
     */
68
    public function build()
69
    {
70
        $sql = [
71
            $this->from->build(),
72
            $this->where->build(),
73
            $this->orderBy->build(),
74
            $this->limit->build(),
75
        ];
76
77
        $this->values = $this->where->getValues();
78
79
        return implode(' ', array_filter($sql));
80
    }
81
82
    public function __clone()
83
    {
84
        $this->from = clone $this->from;
85
        $this->where = clone $this->where;
86
        $this->orderBy = clone $this->orderBy;
87
        $this->limit = clone $this->limit;
88
    }
89
}
90