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

GeometryField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 29
ccs 15
cts 16
cp 0.9375
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeField() 0 20 4
A __construct() 0 3 1
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