Conditions | 12 |
Paths | 11 |
Total Lines | 35 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 23 |
CRAP Score | 12.0104 |
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 |
||
26 | 1 | public static function findClassInFile($file) |
|
27 | { |
||
28 | 1 | $class = false; |
|
29 | 1 | $namespace = false; |
|
30 | 1 | $tokens = token_get_all(file_get_contents($file)); |
|
31 | 1 | for ($i = 0, $count = count($tokens); $i < $count; ++$i) { |
|
32 | 1 | $token = $tokens[$i]; |
|
33 | |||
34 | 1 | if (!is_array($token)) { |
|
35 | 1 | continue; |
|
36 | } |
||
37 | |||
38 | 1 | if (true === $class && T_STRING === $token[0]) { |
|
39 | 1 | return $namespace.'\\'.$token[1]; |
|
40 | } |
||
41 | |||
42 | 1 | if (true === $namespace && T_STRING === $token[0]) { |
|
43 | 1 | $namespace = ''; |
|
44 | do { |
||
45 | 1 | $namespace .= $token[1]; |
|
46 | 1 | $token = $tokens[++$i]; |
|
47 | 1 | } while ($i < $count && is_array($token) && in_array($token[0], array(T_NS_SEPARATOR, T_STRING))); |
|
48 | 1 | } |
|
49 | |||
50 | 1 | if (T_CLASS === $token[0]) { |
|
51 | 1 | $class = true; |
|
52 | 1 | } |
|
53 | |||
54 | 1 | if (T_NAMESPACE === $token[0]) { |
|
55 | 1 | $namespace = true; |
|
56 | 1 | } |
|
57 | 1 | } |
|
58 | |||
59 | return false; |
||
60 | } |
||
61 | } |
||
62 |