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