Test Failed
Branch master (1fbe3c)
by Aleksandr
02:14
created

IndexColumn::getTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
4
namespace carono\yii2migrate;
5
6
7
class IndexColumn
8
{
9
    /**
10
     * @var Migration
11
     */
12
    public $migrate;
13
    protected $_unique;
14
    protected $_name;
15
    protected $_columns;
16
    protected $_table;
17
18
    /**
19
     * @param $migrate
20
     * @return $this
21
     */
22
    public function setMigrate($migrate)
23
    {
24
        $this->migrate = $migrate;
25
        return $this;
26
    }
27
28
    /**
29
     * @param bool $value
30
     * @return $this
31
     */
32
    public function unique($value = true)
33
    {
34
        $this->_unique = $value;
35
        return $this;
36
    }
37
38
    /**
39
     * @param $name
40
     * @return $this
41
     */
42
    public function name($name)
43
    {
44
        $this->_name = $name;
45
        return $this;
46
    }
47
48
    /**
49
     * @param array $columns
50
     * @return IndexColumn
51
     */
52
    public function columns($columns)
53
    {
54
        $this->_columns = $columns;
55
        return $this;
56
    }
57
58
    /**
59
     * @param $table
60
     * @return $this
61
     */
62
    public function table($table)
63
    {
64
        $this->_table = $table;
65
        return $this;
66
    }
67
68
    /**
69
     * @return mixed
70
     */
71
    public function getTable()
72
    {
73
        return $this->_table;
74
    }
75
76
    /**
77
     * @return mixed
78
     */
79
    public function getColumns()
80
    {
81
        return $this->_columns;
82
    }
83
84
    /**
85
     * @return mixed
86
     */
87
    public function getUnique()
88
    {
89
        return $this->_unique;
90
    }
91
92
    public function formIndexName()
93
    {
94
        $unique = $this->_unique;
95
        $columns = $this->_columns;
96
        if (!$this->_name) {
97
            $indexName = Migration::formIndexName($this->_table, $columns, $unique ? '_unq' : '_idx', $this->migrate->db->tablePrefix);
98
            $name = $this->migrate->expandTablePrefix($indexName);
99
        } else {
100
            $name = $this->_name;
101
        }
102
        return $name;
103
    }
104
105
    public function apply()
106
    {
107
        $this->migrate->createIndex($this->formIndexName(), $this->_table, $this->_columns, $this->_unique);
108
    }
109
110
    public function remove()
111
    {
112
        $this->migrate->dropIndex($this->formIndexName(), $this->_table);
113
    }
114
115
    public function getName()
116
    {
117
        return $this->_name;
118
    }
119
}