Conditions | 10 |
Paths | 9 |
Total Lines | 41 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Tests | 24 |
CRAP Score | 10 |
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 |
||
52 | 45 | private function getConfigClass($contents) |
|
53 | { |
||
54 | 45 | $namespace = []; |
|
55 | 45 | $class = []; |
|
56 | |||
57 | 45 | $tokens = token_get_all($contents); |
|
58 | |||
59 | do { |
||
60 | 45 | $token = current($tokens); |
|
61 | |||
62 | 45 | if (isset($token[0]) && T_NAMESPACE === $token[0]) { |
|
63 | 45 | next($tokens); |
|
64 | do { |
||
65 | 45 | $token = current($tokens); |
|
66 | 45 | if (';' === $token) { |
|
67 | 45 | break 1; |
|
68 | } |
||
69 | 45 | $namespace[] = $token[1]; |
|
70 | 45 | } while (next($tokens)); |
|
71 | |||
72 | 45 | $namespace = trim(implode('', $namespace)); |
|
73 | } |
||
74 | |||
75 | 45 | if (isset($token[0]) && T_CLASS === $token[0]) { |
|
76 | 45 | next($tokens); |
|
77 | do { |
||
78 | 45 | $token = current($tokens); |
|
79 | |||
80 | 45 | if (T_STRING === $token[0]) { |
|
81 | 45 | $class[] = $token[1]; |
|
82 | 45 | break 1; |
|
83 | } |
||
84 | 45 | } while (next($tokens)); |
|
85 | |||
86 | 45 | $class = trim(implode('', $class)); |
|
87 | |||
88 | 45 | break; |
|
89 | } |
||
90 | 45 | } while (next($tokens)); |
|
91 | |||
92 | 45 | return (string) $namespace.'\\'.(string) $class; |
|
93 | } |
||
95 |