Conditions | 13 |
Paths | 5 |
Total Lines | 32 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 1 |
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 |
||
21 | public function setBody($params = null) |
||
22 | { |
||
23 | if (isset($this->index)) { |
||
24 | $columns = []; |
||
25 | if (isset($params['columns'])) { |
||
26 | foreach ($params['columns'] as $name => $settings) { |
||
27 | $column = '`' . $name . '` ' . $settings['type']; |
||
28 | if (isset($settings['options']) && count($settings['options']) > 0) { |
||
29 | $column .= ' ' . implode(' ', $settings['options']); |
||
30 | } |
||
31 | $columns[] = $column; |
||
32 | } |
||
33 | } |
||
34 | $options = ""; |
||
35 | if (isset($params['settings'])) { |
||
36 | foreach ($params['settings'] as $name => $value) { |
||
37 | if (is_array($value)) { |
||
38 | foreach ($value as $v) { |
||
39 | $options.=" ".$name." = '".$v."'"; |
||
40 | } |
||
41 | } else { |
||
42 | $options.=" ".$name." = '".$value."'"; |
||
43 | } |
||
44 | } |
||
45 | } |
||
46 | return parent::setBody(['query' => "CREATE TABLE ". |
||
47 | (isset($params['silent']) && $params['silent']===true?' IF NOT EXISTS ':''). |
||
48 | $this->index. |
||
49 | (count($columns)>0?"(".implode(",", $columns).")":" ") |
||
50 | .$options]); |
||
51 | } |
||
52 | throw new RuntimeException('Index name is missing.'); |
||
53 | } |
||
70 |