| Conditions | 15 |
| Paths | 16 |
| Total Lines | 79 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 46 |
| CRAP Score | 15 |
| 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 |
||
| 43 | 6 | public function parseFile() |
|
| 44 | { |
||
| 45 | 6 | $tokens = token_get_all(file_get_contents($this->filename)); |
|
| 46 | |||
| 47 | 6 | $matching = null; |
|
| 48 | 6 | $classname = ''; |
|
| 49 | 6 | $as = ''; |
|
| 50 | 6 | $currentNS = null; |
|
| 51 | |||
| 52 | 6 | foreach ($tokens as $token) |
|
| 53 | { |
||
| 54 | 6 | if ($token === ';') |
|
| 55 | { |
||
| 56 | 6 | $readingClassName = false; |
|
|
|
|||
| 57 | |||
| 58 | switch ($matching) |
||
| 59 | { |
||
| 60 | 6 | case T_NAMESPACE: |
|
| 61 | 6 | $ns = new NamespaceBlock($classname); |
|
| 62 | 6 | $currentNS = new RawPropertyAccessor($ns); |
|
| 63 | 6 | $this->accessor->rawAddToValue |
|
| 64 | ( |
||
| 65 | 6 | 'namespaces', |
|
| 66 | $ns |
||
| 67 | ); |
||
| 68 | 6 | $currentNS->setRawValue('file', $this->object); |
|
| 69 | 6 | $matching = null; |
|
| 70 | 6 | break; |
|
| 71 | 6 | case T_AS: |
|
| 72 | 6 | case T_USE: |
|
| 73 | 6 | if (!$as) |
|
| 74 | { |
||
| 75 | 6 | $as = explode('\\', $classname); |
|
| 76 | 6 | $as = end($as); |
|
| 77 | } |
||
| 78 | |||
| 79 | 6 | $currentNS->rawAddToValue |
|
| 80 | ( |
||
| 81 | 6 | 'useStatements', |
|
| 82 | 6 | new UseStatement($classname, $as) |
|
| 83 | ); |
||
| 84 | 6 | $matching = null; |
|
| 85 | 6 | break; |
|
| 86 | } |
||
| 87 | 6 | continue; |
|
| 88 | } |
||
| 89 | |||
| 90 | 6 | if ($matching === T_AS) |
|
| 91 | { |
||
| 92 | 5 | if ($token[0] === T_STRING) |
|
| 93 | { |
||
| 94 | 5 | $as .= $token[1]; |
|
| 95 | } |
||
| 96 | } |
||
| 97 | 6 | elseif ($matching) |
|
| 98 | { |
||
| 99 | 6 | switch ($token[0]) |
|
| 100 | { |
||
| 101 | 6 | case T_STRING: |
|
| 102 | 6 | case T_NS_SEPARATOR: |
|
| 103 | 6 | $classname .= $token[1]; |
|
| 104 | 6 | break; |
|
| 105 | 6 | case T_AS: |
|
| 106 | 6 | $matching = T_AS; |
|
| 107 | } |
||
| 108 | } |
||
| 109 | else |
||
| 110 | { |
||
| 111 | 6 | switch ($token[0]) |
|
| 112 | { |
||
| 113 | 6 | case T_NAMESPACE: |
|
| 114 | 6 | case T_USE: |
|
| 115 | 6 | $as = ''; |
|
| 116 | 6 | $classname = ''; |
|
| 117 | 6 | $matching = $token[0]; |
|
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | 6 | } |
|
| 122 | } |
||
| 123 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.