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

OtherField::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
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