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; |
4 | |
5 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
6 | use Doctrine\DBAL\Types\PhpIntegerMappingType; |
7 | use Doctrine\DBAL\Types\Type; |
8 | |
9 | /** |
10 | * Handling smallest integer data type |
11 | */ |
12 | class TinyIntType extends Type implements PhpIntegerMappingType { |
13 | public const TINYINT = 'mwtinyint'; |
14 | |
15 | public function getSQLDeclaration( array $fieldDeclaration, AbstractPlatform $platform ) { |
16 | if ( $platform->getName() == 'mysql' ) { |
17 | if ( !empty( $fieldDeclaration['length'] ) && is_numeric( $fieldDeclaration['length'] ) ) { |
18 | $length = $fieldDeclaration['length']; |
19 | return "TINYINT($length)" . $this->getCommonIntegerTypeDeclarationForMySQL( $fieldDeclaration ); |
20 | } |
21 | return 'TINYINT' . $this->getCommonIntegerTypeDeclarationForMySQL( $fieldDeclaration ); |
22 | } |
23 | |
24 | return $platform->getSmallIntTypeDeclarationSQL( $fieldDeclaration ); |
25 | } |
26 | |
27 | protected function getCommonIntegerTypeDeclarationForMySQL( array $columnDef ) { |
28 | $autoinc = ''; |
29 | if ( !empty( $columnDef['autoincrement'] ) ) { |
30 | $autoinc = ' AUTO_INCREMENT'; |
31 | } |
32 | |
33 | return !empty( $columnDef['unsigned'] ) ? ' UNSIGNED' . $autoinc : $autoinc; |
34 | } |
35 | |
36 | public function getName() { |
37 | return self::TINYINT; |
38 | } |
39 | } |