Conditions | 20 |
Paths | > 20000 |
Total Lines | 66 |
Code Lines | 45 |
Lines | 66 |
Ratio | 100 % |
Changes | 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 |
||
150 | public function create_table($table, $definition, $index=array()) |
||
151 | { |
||
152 | $create_sql = "CREATE TABLE $table ("; |
||
153 | if (!is_array($definition)) { |
||
154 | throw new KumbiaException("Definición invalida para crear la tabla '$table'"); |
||
155 | } |
||
156 | $create_lines = array(); |
||
157 | $index = array(); |
||
158 | $unique_index = array(); |
||
159 | $primary = array(); |
||
160 | //$not_null = ""; |
||
161 | //$size = ""; |
||
162 | foreach ($definition as $field => $field_def) { |
||
163 | if (isset($field_def['not_null'])) { |
||
164 | $not_null = $field_def['not_null'] ? 'NOT NULL' : ''; |
||
165 | } else { |
||
166 | $not_null = ""; |
||
167 | } |
||
168 | if (isset($field_def['size'])) { |
||
169 | $size = $field_def['size'] ? '(' . $field_def['size'] . ')' : ''; |
||
170 | } else { |
||
171 | $size = ""; |
||
172 | } |
||
173 | if (isset($field_def['index'])) { |
||
174 | if ($field_def['index']) { |
||
175 | $index[] = "INDEX($field)"; |
||
176 | } |
||
177 | } |
||
178 | if (isset($field_def['unique_index'])) { |
||
179 | if ($field_def['unique_index']) { |
||
180 | $index[] = "UNIQUE($field)"; |
||
181 | } |
||
182 | } |
||
183 | if (isset($field_def['primary'])) { |
||
184 | if ($field_def['primary']) { |
||
185 | $primary[] = "$field"; |
||
186 | } |
||
187 | } |
||
188 | if (isset($field_def['auto'])) { |
||
189 | if ($field_def['auto']) { |
||
190 | $not_null = ""; |
||
191 | } |
||
192 | } |
||
193 | if (isset($field_def['extra'])) { |
||
194 | $extra = $field_def['extra']; |
||
195 | } else { |
||
196 | $extra = ""; |
||
197 | } |
||
198 | $create_lines[] = "$field " . $field_def['type'] . $size . ' ' . $not_null . ' ' . $extra; |
||
199 | } |
||
200 | $create_sql.= join(',', $create_lines); |
||
201 | $last_lines = array(); |
||
202 | if (count($primary)) { |
||
203 | $last_lines[] = 'PRIMARY KEY(' . join(",", $primary) . ')'; |
||
204 | } |
||
205 | if (count($index)) { |
||
206 | $last_lines[] = join(',', $index); |
||
207 | } |
||
208 | if (count($unique_index)) { |
||
209 | $last_lines[] = join(',', $unique_index); |
||
210 | } |
||
211 | if (count($last_lines)) { |
||
212 | $create_sql.= ',' . join(',', $last_lines) . ')'; |
||
213 | } |
||
214 | return $this->exec($create_sql); |
||
215 | } |
||
216 | |||
255 |