Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
| NumericDataType | |
100.00% |
24 / 24 |
|
100.00% |
9 / 9 |
13 | |
100.00% |
1 / 1 |
| autoIncrement | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| renderAutoIncrement | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| signed | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| renderSigned | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| unsigned | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| renderUnsigned | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| zerofill | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| renderZerofill | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| renderTypeAttributes | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 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\Columns\Numeric; |
| 11 | |
| 12 | use Framework\Database\Definition\Table\Columns\Column; |
| 13 | |
| 14 | /** |
| 15 | * Class NumericDataType. |
| 16 | * |
| 17 | * @package database |
| 18 | */ |
| 19 | abstract class NumericDataType extends Column |
| 20 | { |
| 21 | protected bool $signed = false; |
| 22 | protected bool $unsigned = false; |
| 23 | protected bool $zerofill = false; |
| 24 | protected bool $autoIncrement = false; |
| 25 | |
| 26 | /** |
| 27 | * @see https://mariadb.com/kb/en/auto_increment/ |
| 28 | * |
| 29 | * @return static |
| 30 | */ |
| 31 | public function autoIncrement() : static |
| 32 | { |
| 33 | $this->autoIncrement = true; |
| 34 | return $this; |
| 35 | } |
| 36 | |
| 37 | protected function renderAutoIncrement() : ?string |
| 38 | { |
| 39 | if ( ! $this->autoIncrement) { |
| 40 | return null; |
| 41 | } |
| 42 | return ' AUTO_INCREMENT'; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @return static |
| 47 | */ |
| 48 | public function signed() : static |
| 49 | { |
| 50 | $this->signed = true; |
| 51 | return $this; |
| 52 | } |
| 53 | |
| 54 | protected function renderSigned() : ?string |
| 55 | { |
| 56 | if ( ! $this->signed) { |
| 57 | return null; |
| 58 | } |
| 59 | return ' signed'; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @return static |
| 64 | */ |
| 65 | public function unsigned() : static |
| 66 | { |
| 67 | $this->unsigned = true; |
| 68 | return $this; |
| 69 | } |
| 70 | |
| 71 | protected function renderUnsigned() : ?string |
| 72 | { |
| 73 | if ( ! $this->unsigned) { |
| 74 | return null; |
| 75 | } |
| 76 | return ' unsigned'; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @return static |
| 81 | */ |
| 82 | public function zerofill() : static |
| 83 | { |
| 84 | $this->zerofill = true; |
| 85 | return $this; |
| 86 | } |
| 87 | |
| 88 | protected function renderZerofill() : ?string |
| 89 | { |
| 90 | if ( ! $this->zerofill) { |
| 91 | return null; |
| 92 | } |
| 93 | return ' zerofill'; |
| 94 | } |
| 95 | |
| 96 | protected function renderTypeAttributes() : ?string |
| 97 | { |
| 98 | return $this->renderSigned() |
| 99 | . $this->renderUnsigned() |
| 100 | . $this->renderZerofill() |
| 101 | . $this->renderAutoIncrement(); |
| 102 | } |
| 103 | } |