Completed
Push — master ( d1d2ef...0e04b4 )
by Kit Loong
04:05
created

GeometryField::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\Generators;
9
10
use KitLoong\MigrationsGenerator\MigrationsGeneratorSetting;
11
use KitLoong\MigrationsGenerator\MigrationMethod\PgSQLGeography;
12
use KitLoong\MigrationsGenerator\Repositories\PgSQLRepository;
13
14
class GeometryField
15
{
16
    private $pgsqlRepository;
17
18 57
    public function __construct(PgSQLRepository $pgSQLRepository)
19
    {
20 57
        $this->pgsqlRepository = $pgSQLRepository;
21 57
    }
22
23 6
    public function makeField(string $tableName, array $field)
24
    {
25
        /** @var MigrationsGeneratorSetting $setting */
26 6
        $setting = app(MigrationsGeneratorSetting::class);
27
28 6
        switch ($setting->getPlatform()) {
29 2
            case Platform::POSTGRESQL:
30 6
                $columnType = $this->pgsqlRepository->getTypeByColumnName($tableName, $field['field']);
31 6
                if ($columnType !== null) {
32 6
                    $type = strtolower($columnType);
33 6
                    $type = preg_replace('/\s+/', '', $type);
34
35 6
                    if (isset(PgSQLGeography::MAP[$type])) {
36 6
                        $field['type'] = PgSQLGeography::MAP[$type];
37
                    }
38
                }
39 6
                break;
40
            default:
41
        }
42 6
        return $field;
43
    }
44
}
45