Completed
Push — master ( 2a503e...626ee6 )
by Kit Loong
01:12
created

MigrationGeneratorSetting   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConnection() 0 4 1
A setConnection() 0 28 5
A getDatabasePlatform() 0 4 1
A getPlatform() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: liow.kitloong
5
 * Date: 2020/03/31
6
 * Time: 22:55
7
 */
8
9
namespace KitLoong\MigrationsGenerator;
10
11
use Illuminate\Support\Facades\DB;
12
use KitLoong\MigrationsGenerator\Generators\Platform;
13
14
class MigrationGeneratorSetting
15
{
16
    /**
17
     * @var string
18
     */
19
    private $connection;
20
21
    /**
22
     * @var \Doctrine\DBAL\Platforms\AbstractPlatform
23
     */
24
    private $databasePlatform;
25
26
    /**
27
     * @var string
28
     */
29
    private $platform;
30
31
    /**
32
     * @return string
33
     */
34
    public function getConnection(): string
35
    {
36
        return $this->connection;
37
    }
38
39
    /**
40
     * @param  string  $connection
41
     */
42
    public function setConnection(string $connection): void
43
    {
44
        $this->connection = $connection;
45
46
        /** @var \Doctrine\DBAL\Connection $doctConn */
47
        $doctConn = DB::connection($this->connection)->getDoctrineConnection();
48
        $this->databasePlatform = $doctConn->getDatabasePlatform();
49
        $classPath = explode('\\', get_class($this->databasePlatform));
50
        $platform = end($classPath);
51
52
        switch (true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/mysql/i', $platform) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/postgresql/i', $platform) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/sqlserver/i', $platform) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/sqlite/i', $platform) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
53
            case preg_match('/mysql/i', $platform):
54
                $this->platform = Platform::MYSQL;
55
                break;
56
            case preg_match('/postgresql/i', $platform):
57
                $this->platform = Platform::POSTGRESQL;
58
                break;
59
            case preg_match('/sqlserver/i', $platform):
60
                $this->platform = Platform::SQLSERVER;
61
                break;
62
            case preg_match('/sqlite/i', $platform):
63
                $this->platform = Platform::SQLITE;
64
                break;
65
            default:
66
                $this->platform = Platform::OTHERS;
67
                break;
68
        }
69
    }
70
71
    /**
72
     * @return \Doctrine\DBAL\Platforms\AbstractPlatform
73
     */
74
    public function getDatabasePlatform(): \Doctrine\DBAL\Platforms\AbstractPlatform
75
    {
76
        return $this->databasePlatform;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getPlatform(): string
83
    {
84
        return $this->platform;
85
    }
86
}
87