Conditions | 19 |
Paths | 1323 |
Total Lines | 101 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
90 | private function tableInformations($table) |
||
91 | { |
||
92 | $foreignKeys = $this->schema->getConnection()->getForeignKeys($table); |
||
93 | |||
94 | $columns = $this->schema->getConnection()->showColumnsFrom($table); |
||
95 | |||
96 | $status = $this->schema->getConnection()->getTableStatus($table); |
||
97 | |||
98 | $indexes = $this->schema->getConnection()->showIndexes($table); |
||
99 | $multipleIndexes = $this->getMultipleIndex($indexes); |
||
100 | |||
101 | |||
102 | $list = []; |
||
103 | |||
104 | foreach ($columns as $key=>$data){ |
||
105 | |||
106 | $data['Type'] = rtrim(str_replace('unsigned','',$data['Type'])); |
||
107 | |||
108 | $field = $data['Field']; |
||
109 | $list[] = '$wizard->name(\''.$field.'\')'; |
||
110 | $list[] = '->'.$this->getColumnTransformers($data['Type']).''; |
||
111 | |||
112 | //default block |
||
113 | if(!is_null($data['Default'])){ |
||
114 | $default = $data['Default']; |
||
115 | $list[] = '->default(\''.$default.'\')'; |
||
116 | } |
||
117 | |||
118 | $getIndex = $this->getIndexInformation($indexes,$data['Field']); |
||
119 | |||
120 | //unique block |
||
121 | if($getIndex['Non_unique']=='0' && $getIndex['Key_name']!=='PRIMARY'){ |
||
122 | $indexName = $getIndex['Key_name']; |
||
123 | $list[] = '->unique(\''.$indexName.'\')'; |
||
124 | } |
||
125 | |||
126 | //index block |
||
127 | if($getIndex['Non_unique']=='1' && $getIndex['Key_name']!=='PRIMARY'){ |
||
128 | $columnName = $getIndex['Column_name']; |
||
|
|||
129 | $indexName = $getIndex['Key_name']; |
||
130 | |||
131 | if(count($multipleIndexes[$indexName])==1){ |
||
132 | $list[] = '->index(\''.$indexName.'\')'; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | //comment block |
||
137 | if(strlen($data['Comment'])>0){ |
||
138 | $comment = $data['Comment']; |
||
139 | $list[] = '->comment(\''.$comment.'\')'; |
||
140 | } |
||
141 | |||
142 | //auto increment block |
||
143 | if($data['Extra']=='auto_increment'){ |
||
144 | $list[] = '->auto_increment()'; |
||
145 | } |
||
146 | |||
147 | $list[] = '; |
||
148 | '; |
||
149 | } |
||
150 | |||
151 | //table collation |
||
152 | $charset = $this->schema->getConnection()->getCharsetForCollation(''.$status['Collation'].''); |
||
153 | $list[] = '$wizard->table()->collation(\''.$charset.'\'); |
||
154 | '; |
||
155 | |||
156 | //table indexes |
||
157 | foreach ($multipleIndexes as $indexName=>$values) { |
||
158 | if(count($values)>1){ |
||
159 | $values = '\''.implode('\',\'',$values).'\''; |
||
160 | $list[] = ' $wizard->table()->indexes(\''.$indexName.'\',['.$values.']); |
||
161 | '; |
||
162 | } |
||
163 | } |
||
164 | |||
165 | if(count($foreignKeys)){ |
||
166 | |||
167 | $constraintName = $foreignKeys['CONSTRAINT_NAME']; |
||
168 | $key = $foreignKeys['COLUMN_NAME']; |
||
169 | $referenceTable = $foreignKeys['REFERENCED_TABLE_NAME']; |
||
170 | $referenceColumn = $foreignKeys['REFERENCED_COLUMN_NAME']; |
||
171 | |||
172 | if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
||
173 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\'); |
||
174 | '; |
||
175 | } |
||
176 | |||
177 | if($foreignKeys['UPDATE_RULE']!=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
||
178 | $rule = $foreignKeys['UPDATE_RULE']; |
||
179 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onUpdate()->'.strtolower($rule).'(); |
||
180 | '; |
||
181 | } |
||
182 | |||
183 | if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']!=='RESTRICT'){ |
||
184 | $rule = $foreignKeys['DELETE_RULE']; |
||
185 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onDelete()->'.strtolower($rule).'(); |
||
186 | '; |
||
187 | } |
||
188 | } |
||
189 | |||
190 | return implode('',$list); |
||
191 | } |
||
279 | } |