Conditions | 10 |
Paths | 10 |
Total Lines | 43 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
36 | public function resolve($string) |
||
37 | { |
||
38 | $string = $cased = trim($string, ";\t\n\r\0\x0B"); |
||
39 | $string = strtolower($string); |
||
40 | |||
41 | if(strlen($string) == 0) { |
||
42 | return self::TYPE_VOID; |
||
43 | } |
||
44 | |||
45 | if(preg_match('!^\d+$!', $string)) { |
||
46 | return self::TYPE_INTEGER; |
||
47 | } |
||
48 | |||
49 | if(preg_match('!^\d+\.\d+$!', $string)) { |
||
50 | return self::TYPE_FLOAT; |
||
51 | } |
||
52 | |||
53 | if('null' == $string) { |
||
54 | return self::TYPE_NULL; |
||
55 | } |
||
56 | |||
57 | if(preg_match('!(^\[|^array\()!', $string)) { |
||
58 | return self::TYPE_ARRAY; |
||
59 | } |
||
60 | |||
61 | if(preg_match('!(^\[|^array\()!', $string)) { |
||
62 | return self::TYPE_ARRAY; |
||
63 | } |
||
64 | |||
65 | if(preg_match('!^new\s*(.*)!', $string, $matches)) { |
||
66 | return trim(preg_replace('!^(new\s+)!', '', $cased)); |
||
67 | } |
||
68 | |||
69 | if(preg_match('!^\$this$!', $string, $matches)) { |
||
70 | return self::TYPE_FLUENT_INTERFACE; |
||
71 | } |
||
72 | |||
73 | if(preg_match('!^["\']!', $string, $matches)) { |
||
74 | return self::TYPE_STRING; |
||
75 | } |
||
76 | |||
77 | return self::TYPE_UNKNWON; |
||
78 | } |
||
79 | |||
100 | } |