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

OtherField::makeField()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 8
nop 3
dl 0
loc 17
ccs 0
cts 0
cp 0
crap 20
rs 9.9666
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