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