MySQLRepository::getSetPresetValues()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 15
ccs 10
cts 10
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: liow.kitloong
5
 * Date: 2020/04/07
6
 */
7
8
namespace KitLoong\MigrationsGenerator\Repositories;
9
10
use KitLoong\MigrationsGenerator\MigrationsGeneratorSetting;
11
12
class MySQLRepository
13
{
14 6
    public function getEnumPresetValues(string $table, string $columnName): ?string
15
    {
16
        /** @var MigrationsGeneratorSetting $setting */
17 6
        $setting = app(MigrationsGeneratorSetting::class);
18
19 6
        $column = $setting->getConnection()->select("SHOW COLUMNS FROM `${table}` where Field = '${columnName}' AND Type LIKE 'enum(%'");
20 6
        if (count($column) > 0) {
21 3
            return substr(
22 3
                str_replace('enum(', '[', $this->spaceAfterComma($column[0]->Type)),
23 3
                0,
24 3
                -1
25 3
            ).']';
26
        }
27 3
        return null;
28
    }
29
30 6
    public function getSetPresetValues(string $table, string $columnName): ?string
31
    {
32
        /** @var MigrationsGeneratorSetting $setting */
33 6
        $setting = app(MigrationsGeneratorSetting::class);
34
35 6
        $column = $setting->getConnection()->select("SHOW COLUMNS FROM `${table}` where Field = '${columnName}' AND Type LIKE 'set(%'");
36 6
        if (count($column) > 0) {
37 3
            return substr(
38 3
                str_replace('set(', '[', $this->spaceAfterComma($column[0]->Type)),
39 3
                0,
40 3
                -1
41 3
            ).']';
42
        }
43
44 3
        return null;
45
    }
46
47 6
    private function spaceAfterComma(string $value): string
48
    {
49 6
        return str_replace("','", "', '", $value);
50
    }
51
}
52