MysqliMapping::getDatatypeMapping()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 29
cts 29
cp 1
rs 9.0472
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\Metadata\Reader\Mapping;
6
7
use Soluble\Datatype\Column;
8
use ArrayObject;
9
10
class MysqliMapping
11
{
12 4
    public static function getDatatypeMapping(): ArrayObject
13
    {
14
        /*
15
        // ALL the following fields are not supported yet
16
        // Maybe todo in a later release or choose to map them to approximative
17
        // types
18
          MYSQLI_TYPE_YEAR -> int
19
          MYSQLI_TYPE_ENUM -> string
20
          MYSQLI_TYPE_SET -> string
21
         */
22
23 4
        $mapping = new ArrayObject([
24 4
            MYSQLI_TYPE_STRING => ['type' => Column\Type::TYPE_STRING, 'native' => 'VARCHAR'],
25 4
            MYSQLI_TYPE_CHAR => ['type' => Column\Type::TYPE_STRING, 'native' => 'CHAR'],
26 4
            MYSQLI_TYPE_VAR_STRING => ['type' => Column\Type::TYPE_STRING, 'native' => 'VARCHAR'],
27 4
            MYSQLI_TYPE_ENUM => ['type' => Column\Type::TYPE_STRING, 'native' => 'ENUM'],
28
            // BLOBS ARE CURRENTLY SENT AS TEXT
29
            // I DIDN'T FIND THE WAY TO MAKE THE DIFFERENCE !!!
30 4
            MYSQLI_TYPE_TINY_BLOB => ['type' => Column\Type::TYPE_BLOB, 'native' => 'TINYBLOB'],
31 4
            MYSQLI_TYPE_MEDIUM_BLOB => ['type' => Column\Type::TYPE_BLOB, 'native' => 'MEDIUMBLOB'],
32 4
            MYSQLI_TYPE_LONG_BLOB => ['type' => Column\Type::TYPE_BLOB, 'native' => 'LONGBLOB'],
33 4
            MYSQLI_TYPE_BLOB => ['type' => Column\Type::TYPE_BLOB, 'native' => 'BLOB'],
34
            // integer
35 4
            MYSQLI_TYPE_TINY => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'TINYINT'],
36 4
            MYSQLI_TYPE_YEAR => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'YEAR'],
37 4
            MYSQLI_TYPE_SHORT => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'SMALLINT'],
38 4
            MYSQLI_TYPE_INT24 => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'MEDIUMINT'],
39 4
            MYSQLI_TYPE_LONG => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'INTEGER'],
40 4
            MYSQLI_TYPE_LONGLONG => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'BIGINT'],
41
            // timestamps
42 4
            MYSQLI_TYPE_TIMESTAMP => ['type' => Column\Type::TYPE_DATETIME, 'native' => 'TIMESTAMP'],
43 4
            MYSQLI_TYPE_DATETIME => ['type' => Column\Type::TYPE_DATETIME, 'native' => 'DATETIME'],
44
            // dates
45 4
            MYSQLI_TYPE_DATE => ['type' => Column\Type::TYPE_DATE, 'native' => 'DATE'],
46 4
            MYSQLI_TYPE_NEWDATE => ['type' => Column\Type::TYPE_DATE, 'native' => 'DATE'],
47
            // time
48 4
            MYSQLI_TYPE_TIME => ['type' => Column\Type::TYPE_TIME, 'native' => 'TIME'],
49
            // decimals
50 4
            MYSQLI_TYPE_DECIMAL => ['type' => Column\Type::TYPE_DECIMAL, 'native' => 'DECIMAL'],
51 4
            MYSQLI_TYPE_NEWDECIMAL => ['type' => Column\Type::TYPE_DECIMAL, 'native' => 'DECIMAL'],
52 4
            MYSQLI_TYPE_FLOAT => ['type' => Column\Type::TYPE_FLOAT, 'native' => 'FLOAT'],
53 4
            MYSQLI_TYPE_DOUBLE => ['type' => Column\Type::TYPE_FLOAT, 'native' => 'DOUBLE'],
54 4
            MYSQLI_TYPE_BIT => ['type' => Column\Type::TYPE_BIT, 'native' => 'BIT'],
55
            //MYSQLI_TYPE_BOOLEAN => array('type' => Column\Type::TYPE_BOOLEAN, 'native' => 'BOOLEAN'),
56 4
            MYSQLI_TYPE_GEOMETRY => ['type' => Column\Type::TYPE_SPATIAL_GEOMETRY, 'native' => null],
57
            // This type is really annoying, it's when the select contains an aliased null constant
58
            // like 'select null as test_alias'
59 4
            MYSQLI_TYPE_NULL => ['type' => Column\Type::TYPE_NULL, 'native' => 'NULL']
60
        ]);
61
62 4
        return $mapping;
63
    }
64
}
65