Conditions | 12 |
Paths | 9 |
Total Lines | 24 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
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 |
||
14 | public static function tildeField($field, $table = '') |
||
15 | { |
||
16 | $out = ''; |
||
17 | if (!empty($field) && is_scalar($field)) { |
||
18 | if (!empty($table) && is_scalar($table) && $tmp = strpos($field, $table)) { |
||
19 | $tmp = substr($field, $tmp + strlen($table), 1); |
||
20 | if ($tmp != '.' && $tmp != '`') { |
||
21 | $field = $table . "." . $field; |
||
22 | } else { |
||
23 | $out = $field; |
||
24 | } |
||
25 | } elseif (empty($table) && strpos($field, "`")) { |
||
26 | $out = $field; |
||
27 | } |
||
28 | if (empty($out)) { |
||
29 | $field = explode(".", $field); |
||
30 | foreach ($field as &$f) { |
||
31 | $f = "`" . str_replace("`", "", $f) . "`"; |
||
32 | } |
||
33 | $out = implode(".", $field); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | return $out; |
||
38 | } |
||
102 |