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