1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* This file is part of Aura for PHP. |
5
|
|
|
* |
6
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
namespace Aura\SqlQuery\Common; |
10
|
|
|
|
11
|
|
|
use Aura\SqlQuery\AbstractDmlQuery; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* |
15
|
|
|
* An object for DELETE queries. |
16
|
|
|
* |
17
|
|
|
* @package Aura.SqlQuery |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
|
class Delete extends AbstractDmlQuery implements DeleteInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* |
24
|
|
|
* The table to delete from. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
protected $from; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* |
33
|
|
|
* Sets the table to delete from. |
34
|
|
|
* |
35
|
|
|
* @param string $table The table to delete from. |
36
|
|
|
* |
37
|
|
|
* @return $this |
38
|
|
|
* |
39
|
|
|
*/ |
40
|
13 |
|
public function from($table) |
41
|
|
|
{ |
42
|
|
|
$this->from = $this->quoter->quoteName($table); |
|
|
|
|
43
|
13 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* |
48
|
|
|
* Builds this query object into a string. |
49
|
|
|
* |
50
|
|
|
* @return string |
51
|
|
|
* |
52
|
|
|
*/ |
53
|
11 |
|
protected function build() |
54
|
|
|
{ |
55
|
11 |
|
return 'DELETE' |
56
|
|
|
. $this->buildFlags() |
57
|
|
|
. $this->buildFrom() |
58
|
|
|
. $this->buildWhere() |
59
|
|
|
. $this->buildOrderBy() |
60
|
|
|
. $this->buildLimit() |
61
|
|
|
. $this->buildReturning(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* |
66
|
|
|
* Builds the FROM clause. |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
* |
70
|
|
|
*/ |
71
|
11 |
|
protected function buildFrom() |
72
|
|
|
{ |
73
|
11 |
|
return " FROM {$this->from}"; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* |
78
|
|
|
* Adds a WHERE condition to the query by AND. If the condition has |
79
|
|
|
* ?-placeholders, additional arguments to the method will be bound to |
80
|
|
|
* those placeholders sequentially. |
81
|
|
|
* |
82
|
|
|
* @param string $cond The WHERE condition. |
83
|
|
|
* @param mixed ...$bind arguments to bind to placeholders |
84
|
|
|
* |
85
|
|
|
* @return $this |
86
|
|
|
* |
87
|
|
|
*/ |
88
|
|
|
public function where($cond) |
89
|
|
|
{ |
90
|
|
|
$this->addWhere('AND', func_get_args()); |
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* |
96
|
|
|
* Adds a WHERE condition to the query by OR. If the condition has |
97
|
|
|
* ?-placeholders, additional arguments to the method will be bound to |
98
|
|
|
* those placeholders sequentially. |
99
|
|
|
* |
100
|
|
|
* @param string $cond The WHERE condition. |
101
|
|
|
* @param mixed ...$bind arguments to bind to placeholders |
102
|
|
|
* |
103
|
|
|
* @return $this |
104
|
|
|
* |
105
|
|
|
* @see where() |
106
|
|
|
* |
107
|
|
|
*/ |
108
|
10 |
|
public function orWhere($cond) |
109
|
|
|
{ |
110
|
|
|
$this->addWhere('OR', func_get_args()); |
111
|
10 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.