Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
21 / 21 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
| AbstractClause | |
100.00% |
21 / 21 |
|
100.00% |
9 / 9 |
16 | |
100.00% |
1 / 1 |
| setTable | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| hasAlias | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAlias | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setAlias | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getTable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setValues | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| addValue | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
6 | |||
| getValues | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| render | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 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 | * Abstract clause 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 | abstract class AbstractClause extends AbstractSql |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * Table |
| 31 | * @var mixed |
| 32 | */ |
| 33 | protected mixed $table = null; |
| 34 | |
| 35 | /** |
| 36 | * Alias |
| 37 | * @var ?string |
| 38 | */ |
| 39 | protected ?string $alias = null; |
| 40 | |
| 41 | /** |
| 42 | * Values |
| 43 | * @var array |
| 44 | */ |
| 45 | protected array $values = []; |
| 46 | |
| 47 | /** |
| 48 | * Set the table |
| 49 | * |
| 50 | * @param mixed $table |
| 51 | * @return AbstractClause |
| 52 | */ |
| 53 | public function setTable(mixed $table): AbstractClause |
| 54 | { |
| 55 | $this->table = $table; |
| 56 | return $this; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Determine if there is an alias |
| 61 | * |
| 62 | * @return bool |
| 63 | */ |
| 64 | public function hasAlias(): bool |
| 65 | { |
| 66 | return ($this->alias !== null); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Get the alias |
| 71 | * |
| 72 | * @return ?string |
| 73 | */ |
| 74 | public function getAlias(): ?string |
| 75 | { |
| 76 | return $this->alias; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Set the alias |
| 81 | * |
| 82 | * @param string $alias |
| 83 | * @return AbstractClause |
| 84 | */ |
| 85 | public function setAlias(string $alias): AbstractClause |
| 86 | { |
| 87 | $this->alias = $alias; |
| 88 | return $this; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get the table |
| 93 | * |
| 94 | * @return ?string |
| 95 | */ |
| 96 | public function getTable(): ?string |
| 97 | { |
| 98 | return $this->table; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Set the values |
| 103 | * |
| 104 | * @param array $values |
| 105 | * @return AbstractClause |
| 106 | */ |
| 107 | public function setValues(array $values): AbstractClause |
| 108 | { |
| 109 | foreach ($values as $column => $value) { |
| 110 | if ($this->isParameter($value, $column)) { |
| 111 | $values[$column] = $this->getParameter($value, $column); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | $this->values = $values; |
| 116 | return $this; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Add a value |
| 121 | * |
| 122 | * @param mixed $value |
| 123 | * @param ?string $name |
| 124 | * @return AbstractClause |
| 125 | */ |
| 126 | public function addValue(mixed $value, ?string $name = null): AbstractClause |
| 127 | { |
| 128 | if (!is_array($value) && (($value instanceof \Stringable) || !is_object($value))) { |
| 129 | if ($this->isParameter($value, $name)) { |
| 130 | $value = $this->getParameter($value, $name); |
| 131 | } |
| 132 | if ($name !== null) { |
| 133 | $this->values[$name] = $value; |
| 134 | } else { |
| 135 | $this->values[] = $value; |
| 136 | } |
| 137 | } |
| 138 | return $this; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Get the values |
| 143 | * |
| 144 | * @return array |
| 145 | */ |
| 146 | public function getValues(): array |
| 147 | { |
| 148 | return $this->values; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Get a value |
| 153 | * |
| 154 | * @param string $name |
| 155 | * @return mixed |
| 156 | */ |
| 157 | public function getValue(string $name): mixed |
| 158 | { |
| 159 | return $this->values[$name] ?? null; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Render the statement |
| 164 | * |
| 165 | * @return string |
| 166 | */ |
| 167 | abstract public function render(): string; |
| 168 | |
| 169 | } |