Completed
Push — master ( 02cf47...c810a0 )
by Kit Loong
05:10
created

StringField::makeField()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.6666
c 0
b 0
f 0
cc 7
nc 5
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: liow.kitloong
5
 * Date: 2020/03/29
6
 * Time: 14:56
7
 */
8
9
namespace KitLoong\MigrationsGenerator\Generators;
10
11
use Doctrine\DBAL\Schema\Column;
12
use Illuminate\Database\Schema\Builder;
13
use KitLoong\MigrationsGenerator\MigrationMethod\ColumnName;
14
use KitLoong\MigrationsGenerator\MigrationMethod\ColumnType;
15
16
class StringField
17
{
18
    public function makeField(array $field, Column $column): array
19
    {
20
        if ($field['field'] === ColumnName::REMEMBER_TOKEN && $column->getLength() === 100 && !$column->getFixed()) {
21
            $field['type'] = ColumnType::REMEMBER_TOKEN;
22
            $field['field'] = null;
23
            $field['args'] = [];
24
25
            return $field;
26
        }
27
28
        if ($column->getFixed()) {
29
            $field['type'] = ColumnType::CHAR;
30
        }
31
32
        if ($column->getLength() && $column->getLength() !== Builder::$defaultStringLength) {
33
            $field['args'][] = $column->getLength();
34
        }
35
36
        return $field;
37
    }
38
}
39