SchemaBuilderTrait   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
getDb() 0 1 ?
A blob() 0 6 2
A binary() 0 4 1
A varbinary() 0 6 2
A varchar() 0 6 2
A binaryPk() 0 6 2
A tinyInteger() 0 6 2
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
namespace rhosocial\user\migrations;
13
14
use rhosocial\user\migrations\mysql\Schema as MySQLSchema;
15
use yii\db\Schema;
16
use yii\db\Connection;
17
use yii\db\ColumnSchemaBuilder;
18
19
/**
20
 * @version 1.0
21
 * @author vistart <[email protected]>
22
 */
23
trait SchemaBuilderTrait
24
{
25
    /**
26
     * @return Connection the database connection to be used for schema building.
27
     */
28
    protected abstract function getDb();
29
    
30
    /**
31
     * 
32
     * @return ColumnSchemaBuilder
33
     */
34
    public function blob()
35
    {
36
        if ($this->getDb()->driverName == 'mysql') {
37
            return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(MySQLSchema::TYPE_BLOB);
38
        }
39
    }
40
    
41
    /**
42
     * @inheritdoc
43
     */
44
    public function binary($length = null)
45
    {
46
        return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(Schema::TYPE_BINARY, $length);
47
    }
48
    
49
    public function varbinary($length = null)
50
    {
51
        if ($this->getDb()->driverName == 'mysql') {
52
            return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(MySQLSchema::TYPE_VARBINARY, $length);
53
        }
54
    }
55
    
56
    public function varchar($length = null)
57
    {
58
        if ($this->getDb()->driverName == 'mysql') {
59
            return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(MySQLSchema::TYPE_VARCHAR, $length);
60
        }
61
    }
62
    
63
    public function binaryPk()
64
    {
65
        if ($this->getDb()->driverName == 'mysql') {
66
            return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(MySQLSchema::TYPE_BINARY_PK);
67
        }
68
    }
69
    
70
    public function tinyInteger($length = null)
71
    {
72
        if ($this->getDb()->driverName == 'mysql') {
73
            return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(MySQLSchema::TYPE_TINYINT, $length);
74
        }
75
    }
76
}