StringField::makeField()   B
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 10
nc 5
nop 2
dl 0
loc 19
ccs 11
cts 11
cp 1
crap 7
rs 8.8333
c 1
b 0
f 0
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 Illuminate\Database\Schema\Builder;
12
use KitLoong\MigrationsGenerator\MigrationMethod\ColumnName;
13
use KitLoong\MigrationsGenerator\MigrationMethod\ColumnType;
14
15
class StringField
16
{
17 12
    public function makeField(array $field, Column $column): array
18
    {
19 12
        if ($field['field'] === ColumnName::REMEMBER_TOKEN && $column->getLength() === 100 && !$column->getFixed()) {
20 3
            $field['type'] = ColumnType::REMEMBER_TOKEN;
21 3
            $field['field'] = null;
22 3
            $field['args'] = [];
23
24 3
            return $field;
25
        }
26
27 9
        if ($column->getFixed()) {
28 3
            $field['type'] = ColumnType::CHAR;
29
        }
30
31 9
        if ($column->getLength() && $column->getLength() !== Builder::$defaultStringLength) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $column->getLength() of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
32 6
            $field['args'][] = $column->getLength();
33
        }
34
35 9
        return $field;
36
    }
37
}
38