Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Select | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| select | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| renderSelect | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php declare(strict_types=1); |
| 2 | /* |
| 3 | * This file is part of Aplus Framework Database Library. |
| 4 | * |
| 5 | * (c) Natan Felles <natanfelles@gmail.com> |
| 6 | * |
| 7 | * For the full copyright and license information, please view the LICENSE |
| 8 | * file that was distributed with this source code. |
| 9 | */ |
| 10 | namespace Framework\Database\Manipulation\Traits; |
| 11 | |
| 12 | use Closure; |
| 13 | use Framework\Database\Manipulation\Select as SelectStatement; |
| 14 | use LogicException; |
| 15 | |
| 16 | /** |
| 17 | * Trait Select. |
| 18 | * |
| 19 | * @package database |
| 20 | */ |
| 21 | trait Select |
| 22 | { |
| 23 | /** |
| 24 | * Sets the SELECT statement part. |
| 25 | * |
| 26 | * @param Closure $select |
| 27 | * |
| 28 | * @see https://mariadb.com/kb/en/insert-select/ |
| 29 | * |
| 30 | * @return static |
| 31 | */ |
| 32 | public function select(Closure $select) : static |
| 33 | { |
| 34 | $this->sql['select'] = $select(new SelectStatement($this->database)); |
| 35 | return $this; |
| 36 | } |
| 37 | |
| 38 | protected function renderSelect() : ?string |
| 39 | { |
| 40 | if ( ! isset($this->sql['select'])) { |
| 41 | return null; |
| 42 | } |
| 43 | if (isset($this->sql['values'])) { |
| 44 | throw new LogicException('SELECT statement is not allowed when VALUES is set'); |
| 45 | } |
| 46 | if (isset($this->sql['set'])) { |
| 47 | throw new LogicException('SELECT statement is not allowed when SET is set'); |
| 48 | } |
| 49 | return " {$this->sql['select']}"; |
| 50 | } |
| 51 | } |