Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Constraint | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| constraint | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| renderConstraint | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 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\Definition\Table; |
| 11 | |
| 12 | /** |
| 13 | * Trait Constraint. |
| 14 | * |
| 15 | * @package database |
| 16 | */ |
| 17 | trait Constraint |
| 18 | { |
| 19 | protected ?string $constraint = null; |
| 20 | |
| 21 | /** |
| 22 | * @param string $name |
| 23 | * |
| 24 | * @return static |
| 25 | */ |
| 26 | public function constraint(string $name) : static |
| 27 | { |
| 28 | $this->constraint = $name; |
| 29 | return $this; |
| 30 | } |
| 31 | |
| 32 | protected function renderConstraint() : ?string |
| 33 | { |
| 34 | if ($this->constraint === null) { |
| 35 | return null; |
| 36 | } |
| 37 | $constraint = $this->database->protectIdentifier($this->constraint); |
| 38 | return " CONSTRAINT {$constraint}"; |
| 39 | } |
| 40 | } |