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

CollationModifier::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: liow.kitloong
5
 * Date: 2020/11/22
6
 */
7
8
namespace KitLoong\MigrationsGenerator\Generators\Modifier;
9
10
use Doctrine\DBAL\Schema\Column;
11
use KitLoong\MigrationsGenerator\Generators\Decorator;
12
use KitLoong\MigrationsGenerator\MigrationMethod\ColumnModifier;
13
use KitLoong\MigrationsGenerator\MigrationsGeneratorSetting;
14
15
class CollationModifier
16
{
17
    private $decorator;
18
19
    public function __construct(Decorator $decorator)
20
    {
21
        $this->decorator = $decorator;
22
    }
23
24
    public function generate(string $tableName, Column $column): string
0 ignored issues
show
Unused Code introduced by
The parameter $tableName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
    public function generate(/** @scrutinizer ignore-unused */ string $tableName, Column $column): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
//        $setting = app(MigrationsGeneratorSetting::class);
27
//        $tableCollation = $setting->getSchema()->listTableDetails($tableName)->getOptions()['collation'] ?? null;
28
29
        if (app(MigrationsGeneratorSetting::class)->isUseDBCollation()) {
30
            $collation = $column->getPlatformOptions()['collation'] ?? null;
31
            //        if (!empty($column->getPlatformOptions()['collation'])) {
32
            //            if ($columnCollation !== $tableCollation) {
33
            if ($collation != null) {
34
                return $this->decorator->decorate(
35
                    ColumnModifier::COLLATION,
36
                    [$this->decorator->columnDefaultToString($collation)]
37
                );
38
            }
39
        }
40
//            }
41
//        }
42
43
        return '';
44
    }
45
}
46