Completed
Push — 4.x ( da046c...d9a6cf )
by Kit Loong
08:01
created

GeometryField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A makeField() 0 21 4
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\MigrationGeneratorSetting;
11
use KitLoong\MigrationsGenerator\MigrationMethod\PgSQLGeography;
12
use KitLoong\MigrationsGenerator\Repositories\PgSQLRepository;
13
14
class GeometryField
15
{
16
    private $pgsqlRepository;
17
18
    public function __construct(PgSQLRepository $pgSQLRepository)
19
    {
20
        $this->pgsqlRepository = $pgSQLRepository;
21
    }
22
23
    public function makeField(string $tableName, array $field)
24
    {
25
        /** @var MigrationGeneratorSetting $setting */
26
        $setting = app(MigrationGeneratorSetting::class);
27
28
        switch ($setting->getPlatform()) {
29
            case Platform::POSTGRESQL:
30
                $columnType = $this->pgsqlRepository->getTypeByColumnName($tableName, $field['field']);
31
                if ($columnType !== null) {
32
                    $type = strtolower($columnType);
33
                    $type = preg_replace('/\s+/', '', $type);
34
35
                    if (isset(PgSQLGeography::MAP[$type])) {
36
                        $field['type'] = PgSQLGeography::MAP[$type];
37
                    }
38
                }
39
                break;
40
            default:
41
        }
42
        return $field;
43
    }
44
}
45