Total Complexity | 17 |
Total Lines | 124 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 | protected $_length; |
||
18 | |||
19 | 1 | public function length($value) |
|
20 | { |
||
21 | 1 | $this->_length = $value; |
|
22 | 1 | return $this; |
|
23 | } |
||
24 | |||
25 | /** |
||
26 | * @param $migrate |
||
27 | * @return $this |
||
28 | */ |
||
29 | 11 | public function setMigrate($migrate) |
|
30 | { |
||
31 | 11 | $this->migrate = $migrate; |
|
32 | 11 | return $this; |
|
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param bool $value |
||
37 | * @return $this |
||
38 | */ |
||
39 | 11 | public function unique($value = true) |
|
40 | { |
||
41 | 11 | $this->_unique = $value; |
|
42 | 11 | return $this; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param $name |
||
47 | * @return $this |
||
48 | */ |
||
49 | 2 | public function name($name) |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param array $columns |
||
57 | * @return IndexColumn |
||
58 | */ |
||
59 | 11 | public function columns($columns) |
|
60 | { |
||
61 | 11 | $this->_columns = $columns; |
|
62 | 11 | return $this; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param $table |
||
67 | * @return $this |
||
68 | */ |
||
69 | 10 | public function table($table) |
|
70 | { |
||
71 | 10 | $this->_table = $table; |
|
72 | 10 | return $this; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return mixed |
||
77 | */ |
||
78 | 1 | public function getTable() |
|
79 | { |
||
80 | 1 | return $this->_table; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return mixed |
||
85 | */ |
||
86 | 1 | public function getColumns() |
|
87 | { |
||
88 | 1 | return $this->_columns; |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * @return mixed |
||
93 | */ |
||
94 | 1 | public function getUnique() |
|
95 | { |
||
96 | 1 | return $this->_unique; |
|
97 | } |
||
98 | |||
99 | 9 | public function formIndexName() |
|
110 | } |
||
111 | |||
112 | 6 | public function apply() |
|
113 | { |
||
114 | 6 | $columns = $this->_columns; |
|
115 | 6 | if ($this->_length) { |
|
116 | 1 | foreach ($columns as $idx => $column) { |
|
117 | 1 | $columns[$idx] = "{$column}({$this->_length})"; |
|
118 | } |
||
119 | } |
||
120 | 6 | $this->migrate->createIndex($this->formIndexName(), $this->_table, $columns, $this->_unique); |
|
121 | 6 | } |
|
122 | |||
123 | 3 | public function remove() |
|
126 | 3 | } |
|
127 | |||
128 | 1 | public function getName() |
|
131 | } |
||
132 | } |