Lines
100.00%
16 / 16
Functions and Methods
100.00%
4 / 4
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Delete | 100.00% | 16 / 16 | 100.00% | 4 / 4 | 6 | 100.00% | 1 / 1 | |||
| sql | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 2 | |||||
| params | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| reset | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | |||||
| allTablesReferenced | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsbackend\Query\Builder; | |
| 4 | ||
| 5 | /** | |
| 6 | * Update | |
| 7 | * | |
| 8 | * Generates an SQL query for a DELETE operation. | |
| 9 | * | |
| 10 | * @package BO\Zmsbackend\Query\Builder | |
| 11 | * @author Alex Gisby<alex@solution10.com> | |
| 12 | * @license MIT | |
| 13 | */ | |
| 14 | class Delete extends Query | |
| 15 | { | |
| 16 | use TableName; | |
| 17 | use Where; | |
| 18 | use Paginate; | |
| 19 | ||
| 20 | /** | |
| 21 | * @var string The base part of the query | |
| 22 | */ | |
| 23 | protected $queryBase = 'DELETE FROM'; | |
| 24 | ||
| 25 | /** | |
| 26 | * Generates the full SQL statement for this query with all the composite parts. | |
| 27 | * | |
| 28 | * @return string | |
| 29 | */ | |
| 30 | #[\Override] | |
| 31 | public function sql() | |
| 32 | { | |
| 33 | if ($this->table === null) { | |
| 34 | return ''; | |
| 35 | } | |
| 36 | ||
| 37 | $candidateParts = [ | |
| 38 | $this->queryBase, | |
| 39 | $this->dialect->quoteTable($this->table), | |
| 40 | $this->buildWhereSQL($this->dialect), | |
| 41 | $this->buildPaginateSQL() | |
| 42 | ]; | |
| 43 | ||
| 44 | return trim(implode(' ', $candidateParts)); | |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Returns all the parameters, in the correct order, to pass into PDO. | |
| 49 | * | |
| 50 | * @return array | |
| 51 | */ | |
| 52 | #[\Override] | |
| 53 | public function params() | |
| 54 | { | |
| 55 | return $this->getWhereParams(); | |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * Resets the entire query. | |
| 60 | * | |
| 61 | * @return $this | |
| 62 | */ | |
| 63 | #[\Override] | |
| 64 | public function reset() | |
| 65 | { | |
| 66 | $this->table = null; | |
| 67 | $this->resetWhere(); | |
| 68 | return $this; | |
| 69 | } | |
| 70 | ||
| 71 | /* | |
| 72 | * ------------------- All Tables ------------------------ | |
| 73 | */ | |
| 74 | ||
| 75 | /** | |
| 76 | * Returns all the tables that this query makes mention of, in FROMs and JOINs | |
| 77 | * | |
| 78 | * @return array | |
| 79 | */ | |
| 80 | #[\Override] | |
| 81 | public function allTablesReferenced() | |
| 82 | { | |
| 83 | if ($this->table()) { | |
| 84 | return [$this->table()]; | |
| 85 | } | |
| 86 | return []; | |
| 87 | } | |
| 88 | } |