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

CharsetModifier::generate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 13
rs 10
1
<?php
2
3
namespace KitLoong\MigrationsGenerator\Generators\Modifier;
4
5
use Doctrine\DBAL\Schema\Column;
6
use KitLoong\MigrationsGenerator\Generators\Decorator;
7
use KitLoong\MigrationsGenerator\MigrationMethod\ColumnModifier;
8
use KitLoong\MigrationsGenerator\MigrationsGeneratorSetting;
9
10
class CharsetModifier
11
{
12
    private $decorator;
13
14
    public function __construct(Decorator $decorator)
15
    {
16
        $this->decorator = $decorator;
17
    }
18
19
    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

19
    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...
20
    {
21
        if (app(MigrationsGeneratorSetting::class)->isUseDBCollation()) {
22
            $charset = $column->getPlatformOptions()['charset'] ?? null;
23
            if ($charset != null) {
24
                return $this->decorator->decorate(
25
                    ColumnModifier::CHARSET,
26
                    [$this->decorator->columnDefaultToString($charset)]
27
                );
28
            }
29
        }
30
31
        return '';
32
    }
33
}
34