Passed
Push — 4.x ( b027a1...820cf2 )
by Kit Loong
62:09
created

OtherField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 28
ccs 3
cts 3
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeField() 0 17 4
A __construct() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: liow.kitloong
5
 * Date: 2020/03/29
6
 */
7
8
namespace KitLoong\MigrationsGenerator\Generators;
9
10
use Doctrine\DBAL\Schema\Column;
11
use KitLoong\MigrationsGenerator\Generators\Modifier\CharsetModifier;
12 3
use KitLoong\MigrationsGenerator\Generators\Modifier\CollationModifier;
13
14 3
class OtherField
15 3
{
16
    private $collationModifier;
17 3
    private $charsetModifier;
18
19
    public function __construct(CollationModifier $collationModifier, CharsetModifier $charsetModifier)
20
    {
21
        $this->collationModifier = $collationModifier;
22
        $this->charsetModifier = $charsetModifier;
23
    }
24
25
    public function makeField(string $tableName, array $field, Column $column): array
26
    {
27
        if (isset(FieldGenerator::$fieldTypeMap[$field['type']])) {
28
            $field['type'] = FieldGenerator::$fieldTypeMap[$field['type']];
29
        }
30
31
        $charset = $this->charsetModifier->generate($tableName, $column);
32
        if ($charset !== '') {
33
            $field['decorators'][] = $charset;
34
        }
35
36
        $collation = $this->collationModifier->generate($tableName, $column);
37
        if ($collation !== '') {
38
            $field['decorators'][] = $collation;
39
        }
40
41
        return $field;
42
    }
43
}
44