Passed
Push — feature/collation ( e2b273...7d249b )
by Kit Loong
64:57
created

MigrationsGeneratorSetting::setIgnoreIndexNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: liow.kitloong
5
 * Date: 2020/03/31
6
 */
7
8
namespace KitLoong\MigrationsGenerator;
9
10
use Doctrine\DBAL\Schema\AbstractSchemaManager;
11
use Illuminate\Database\Connection;
12
use Illuminate\Support\Facades\DB;
13
use KitLoong\MigrationsGenerator\Generators\Platform;
14
15
class MigrationsGeneratorSetting
16
{
17
    /**
18
     * @var Connection
19
     */
20
    private $connection;
21
22
    /**
23
     * @var string
24
     */
25
    private $platform;
26
27
    /**
28
     * @var AbstractSchemaManager
29
     */
30
    private $schema;
31
32
    /**
33
     * @var boolean
34
     */
35
    private $followCollation;
36
37
    /**
38
     * @var boolean
39
     */
40
    private $ignoreIndexNames;
41
42
    /**
43
     * @var boolean
44
     */
45
    private $ignoreForeignKeyNames;
46
47
    /**
48
     * @return Connection
49
     */
50
    public function getConnection(): Connection
51
    {
52
        return $this->connection;
53
    }
54
55
    /**
56
     * @param  string  $connection
57
     */
58
    public function setConnection(string $connection): void
59
    {
60
        $this->connection = DB::connection($connection);
61
62
        /** @var \Doctrine\DBAL\Connection $doctConn */
63
        $doctConn = $this->connection->getDoctrineConnection();
64
        $this->schema = $doctConn->getSchemaManager();
65
        $classPath = explode('\\', get_class($doctConn->getDatabasePlatform()));
66
        $platform = end($classPath);
67
68
        switch (true) {
69
            case preg_match('/mysql/i', $platform) > 0:
70
                $this->platform = Platform::MYSQL;
71
                break;
72
            case preg_match('/postgresql/i', $platform) > 0:
73
                $this->platform = Platform::POSTGRESQL;
74
                break;
75
            case preg_match('/sqlserver/i', $platform) > 0:
76
                $this->platform = Platform::SQLSERVER;
77
                break;
78
            case preg_match('/sqlite/i', $platform) > 0:
79
                $this->platform = Platform::SQLITE;
80
                break;
81
            default:
82
                $this->platform = Platform::OTHERS;
83
                break;
84
        }
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getPlatform(): string
91
    {
92
        return $this->platform;
93
    }
94
95
    /**
96
     * @return bool
97
     */
98
    public function isFollowCollation(): bool
99
    {
100
        return $this->followCollation;
101
    }
102
103
    /**
104
     * @param  bool  $followCollation
105
     */
106
    public function setFollowCollation(bool $followCollation): void
107
    {
108
        $this->followCollation = $followCollation;
109
    }
110
111
    /**
112
     * @return bool
113
     */
114
    public function isIgnoreIndexNames(): bool
115
    {
116
        return $this->ignoreIndexNames;
117
    }
118
119
    /**
120
     * @param  bool  $ignoreIndexNames
121
     */
122
    public function setIgnoreIndexNames(bool $ignoreIndexNames): void
123
    {
124
        $this->ignoreIndexNames = $ignoreIndexNames;
125
    }
126
127
    /**
128
     * @return bool
129
     */
130
    public function isIgnoreForeignKeyNames(): bool
131
    {
132
        return $this->ignoreForeignKeyNames;
133
    }
134
135
    /**
136
     * @param  bool  $ignoreForeignKeyNames
137
     */
138
    public function setIgnoreForeignKeyNames(bool $ignoreForeignKeyNames): void
139
    {
140
        $this->ignoreForeignKeyNames = $ignoreForeignKeyNames;
141
    }
142
143
    /**
144
     * @return AbstractSchemaManager
145
     */
146
    public function getSchema(): AbstractSchemaManager
147
    {
148
        return $this->schema;
149
    }
150
}
151