Conditions | 5 |
Paths | 1 |
Total Lines | 51 |
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 |
||
24 | public function getFunctions() |
||
25 | { |
||
26 | return array( |
||
27 | new ExpressionFunction('trim', function ($str, $mask = " \t\n\r\0\x0B") { |
||
28 | return sprintf('trim(%1$s, %2$s)', $str, $mask); |
||
29 | }, function ($arguments, $str, $mask = " \t\n\r\0\x0B") { |
||
30 | if (!is_string($str)) { |
||
31 | return $str; |
||
32 | } |
||
33 | |||
34 | return trim($str, $mask); |
||
35 | }), |
||
36 | new ExpressionFunction('explode', function ($str, $expression) { |
||
37 | return sprintf('explode(%1$s, %2$s)', $str, $expression); |
||
38 | }, function ($arguments, $str, $expression) { |
||
39 | if (!is_string($expression)) { |
||
40 | return $expression; |
||
41 | } |
||
42 | |||
43 | return explode($str, $expression); |
||
44 | }), |
||
45 | new ExpressionFunction('empty', function ($expression) { |
||
46 | return sprintf('empty(%1$s)', $expression); |
||
47 | }, function ($arguments, $expression) { |
||
48 | return empty($expression); |
||
49 | }), |
||
50 | new ExpressionFunction('isset', function ($expression) { |
||
51 | return sprintf('isset(%1$s)', $expression); |
||
52 | }, function ($arguments, $expression) { |
||
53 | return isset($expression); |
||
54 | }), |
||
55 | new ExpressionFunction('count', function ($array) { |
||
56 | return sprintf('count(%1$s)', $array); |
||
57 | }, function ($arguments, $array) { |
||
58 | if (!is_array($array)) { |
||
59 | return $array; |
||
60 | } |
||
61 | |||
62 | return count($array); |
||
63 | }), |
||
64 | new ExpressionFunction('array_search', function ($needle, $haystack) { |
||
65 | return sprintf('array_search(%1$s, %2$s)', $needle, $haystack); |
||
66 | }, function ($arguments, $needle, $haystack) { |
||
67 | if (!is_array($haystack)) { |
||
68 | return false; |
||
69 | } |
||
70 | |||
71 | return array_search($needle, $haystack); |
||
72 | }), |
||
73 | ); |
||
74 | } |
||
75 | } |
||
76 |