Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Delete | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
8 | |
100.00% |
1 / 1 |
| from | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| render | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| __toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __get | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Pop PHP Framework (https://www.popphp.org/) |
| 4 | * |
| 5 | * @link https://github.com/popphp/popphp-framework |
| 6 | * @author Nick Sagona, III <dev@noladev.com> |
| 7 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 8 | * @license https://www.popphp.org/license New BSD License |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * @namespace |
| 13 | */ |
| 14 | namespace Pop\Db\Sql; |
| 15 | |
| 16 | /** |
| 17 | * Delete class |
| 18 | * |
| 19 | * @category Pop |
| 20 | * @package Pop\Db |
| 21 | * @author Nick Sagona, III <dev@noladev.com> |
| 22 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 23 | * @license https://www.popphp.org/license New BSD License |
| 24 | * @version 6.7.0 |
| 25 | */ |
| 26 | class Delete extends AbstractPredicateClause |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * Set from table |
| 31 | * |
| 32 | * @param mixed $table |
| 33 | * @return Delete |
| 34 | */ |
| 35 | public function from(mixed $table): Delete |
| 36 | { |
| 37 | $this->setTable($table); |
| 38 | return $this; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Render the DELETE statement |
| 43 | * |
| 44 | * @return string |
| 45 | */ |
| 46 | public function render(): string |
| 47 | { |
| 48 | // Start building the DELETE statement |
| 49 | $sql = 'DELETE FROM ' . $this->quoteId($this->table); |
| 50 | |
| 51 | // Build any WHERE clauses |
| 52 | if ($this->where !== null) { |
| 53 | $sql .= ' WHERE ' . $this->where; |
| 54 | } |
| 55 | |
| 56 | return $sql; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Render the DELETE statement |
| 61 | * |
| 62 | * @return string |
| 63 | */ |
| 64 | public function __toString(): string |
| 65 | { |
| 66 | return $this->render(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Magic method to access $where property |
| 71 | * |
| 72 | * @param string $name |
| 73 | * @throws Exception |
| 74 | * @return mixed |
| 75 | */ |
| 76 | public function __get(string $name): mixed |
| 77 | { |
| 78 | switch (strtolower($name)) { |
| 79 | case 'where': |
| 80 | if ($this->where === null) { |
| 81 | $this->where = new Where($this); |
| 82 | } |
| 83 | return $this->where; |
| 84 | break; |
| 85 | default: |
| 86 | throw new Exception('Not a valid property for this object.'); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | } |