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\From; |
19
|
|
|
use JAQB\Query\Traits\Limit; |
20
|
|
|
use JAQB\Query\Traits\OrderBy; |
21
|
|
|
use JAQB\Query\Traits\Where; |
22
|
|
|
|
23
|
|
|
class DeleteQuery extends AbstractQuery |
24
|
|
|
{ |
25
|
|
|
use Executable, From, Limit, OrderBy, Where; |
26
|
|
|
|
27
|
|
View Code Duplication |
public function __construct() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$this->from = new FromStatement(FromStatement::DELETE); |
|
|
|
|
30
|
|
|
$this->where = new WhereStatement(); |
31
|
|
|
$this->orderBy = new OrderStatement(); |
32
|
|
|
$this->limit = new LimitStatement(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Generates the raw SQL string for the query. |
37
|
|
|
* |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
public function build() |
41
|
|
|
{ |
42
|
|
|
$sql = [ |
43
|
|
|
$this->from->build(), |
44
|
|
|
$this->where->build(), |
45
|
|
|
$this->orderBy->build(), |
46
|
|
|
$this->limit->build(), |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
$this->values = $this->where->getValues(); |
50
|
|
|
|
51
|
|
|
return implode(' ', array_filter($sql)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function __clone() |
55
|
|
|
{ |
56
|
|
|
$this->from = clone $this->from; |
57
|
|
|
$this->where = clone $this->where; |
58
|
|
|
$this->orderBy = clone $this->orderBy; |
59
|
|
|
$this->limit = clone $this->limit; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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.