Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TinyIntType | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
| getSQLDeclaration | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| getCommonIntegerTypeDeclarationForMySQL | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Wikimedia\Rdbms\DBAL; |
| 4 | |
| 5 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 6 | use Doctrine\DBAL\Platforms\MySQLPlatform; |
| 7 | use Doctrine\DBAL\Types\PhpIntegerMappingType; |
| 8 | use Doctrine\DBAL\Types\Type; |
| 9 | |
| 10 | /** |
| 11 | * Handling smallest integer data type |
| 12 | */ |
| 13 | class TinyIntType extends Type implements PhpIntegerMappingType { |
| 14 | public const TINYINT = 'mwtinyint'; |
| 15 | |
| 16 | public function getSQLDeclaration( array $fieldDeclaration, AbstractPlatform $platform ): string { |
| 17 | if ( $platform instanceof MySQLPlatform ) { |
| 18 | if ( !empty( $fieldDeclaration['length'] ) && is_numeric( $fieldDeclaration['length'] ) ) { |
| 19 | $length = $fieldDeclaration['length']; |
| 20 | return "TINYINT($length)" . $this->getCommonIntegerTypeDeclarationForMySQL( $fieldDeclaration ); |
| 21 | } |
| 22 | return 'TINYINT' . $this->getCommonIntegerTypeDeclarationForMySQL( $fieldDeclaration ); |
| 23 | } |
| 24 | |
| 25 | return $platform->getSmallIntTypeDeclarationSQL( $fieldDeclaration ); |
| 26 | } |
| 27 | |
| 28 | protected function getCommonIntegerTypeDeclarationForMySQL( array $columnDef ): string { |
| 29 | $autoinc = ''; |
| 30 | if ( !empty( $columnDef['autoincrement'] ) ) { |
| 31 | $autoinc = ' AUTO_INCREMENT'; |
| 32 | } |
| 33 | |
| 34 | return !empty( $columnDef['unsigned'] ) ? ' UNSIGNED' . $autoinc : $autoinc; |
| 35 | } |
| 36 | |
| 37 | public function getName(): string { |
| 38 | return self::TINYINT; |
| 39 | } |
| 40 | } |