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