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

UpdateQuery::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
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\SetStatement;
18
use JAQB\Statement\WhereStatement;
19
use JAQB\Query\Traits\Limit;
20
use JAQB\Query\Traits\OrderBy;
21
use JAQB\Query\Traits\Where;
22
23
class UpdateQuery extends AbstractQuery
24
{
25
    use Executable, Limit, OrderBy, Where;
26
27
    /**
28
     * @var FromStatement
29
     */
30
    protected $table;
31
32
    /**
33
     * @var SetStatement
34
     */
35
    protected $set;
36
37 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...
38
    {
39
        $this->table = new FromStatement(FromStatement::UPDATE);
40
        $this->set = new SetStatement();
41
        $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...
42
        $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...
43
        $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...
44
    }
45
46
    /**
47
     * Sets the table for the query.
48
     *
49
     * @param string $table table name
50
     *
51
     * @return self
52
     */
53
    public function table($table)
54
    {
55
        $this->table->addTable($table);
56
57
        return $this;
58
    }
59
60
    /**
61
     * Sets the values for the query.
62
     *
63
     * @param array $values
64
     *
65
     * @return self
66
     */
67
    public function values(array $values)
68
    {
69
        $this->set->addValues($values);
70
71
        return $this;
72
    }
73
74
    /**
75
     * Gets the table name for the query.
76
     *
77
     * @return FromStatement
78
     */
79
    public function getTable()
80
    {
81
        return $this->table;
82
    }
83
84
    /**
85
     * Gets the values for the query.
86
     *
87
     * @return array
88
     */
89
    public function getSet()
90
    {
91
        return $this->set;
92
    }
93
94
    /**
95
     * Generates the raw SQL string for the query.
96
     *
97
     * @return string
98
     */
99
    public function build()
100
    {
101
        $sql = [
102
            $this->table->build(),
103
            $this->set->build(),
104
            $this->where->build(),
105
            $this->orderBy->build(),
106
            $this->limit->build(),
107
        ];
108
109
        $this->values = array_merge(
110
            array_values($this->set->getValues()),
111
            $this->where->getValues());
112
113
        return implode(' ', array_filter($sql));
114
    }
115
116
    public function __clone()
117
    {
118
        $this->table = clone $this->table;
119
        $this->set = clone $this->set;
120
        $this->where = clone $this->where;
121
        $this->orderBy = clone $this->orderBy;
122
        $this->limit = clone $this->limit;
123
    }
124
}
125