| Conditions | 22 |
| Paths | 24 |
| Total Lines | 33 |
| Lines | 3 |
| Ratio | 9.09 % |
| 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 |
||
| 18 | function testRuleAppliesToMultilevelIfConditions() |
||
| 19 | { |
||
| 20 | if (1 || 0) { // not applied |
||
| 21 | if (1 == 1 || $foo = 'baz') { // applied |
||
| 22 | // ... |
||
| 23 | } elseif (1 != array() && 'foo' != 'baz' && $bar = 'baz') { // applied |
||
| 24 | // ... |
||
| 25 | } elseif (1 % 2 !== !false && $baz = 1 + 1 + 1 - 3) { // applied |
||
| 26 | // ... |
||
| 27 | if ($foo == 'baz') { // not applied |
||
| 28 | // ... |
||
| 29 | if (3 - 2 == 3) { // not applied |
||
| 30 | // ... |
||
| 31 | if (true) { // not applied |
||
| 32 | // ... |
||
| 33 | if (1) { // not applied |
||
| 34 | // ... |
||
| 35 | } elseif ($foo = 1) { // applied |
||
|
|
|||
| 36 | // ... |
||
| 37 | } elseif ($foo = 2) { // applied |
||
| 38 | // ... |
||
| 39 | } elseif (5 % 5 == 0) { // not applied |
||
| 40 | // ... |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | View Code Duplication | if (1 == 1 || 1 && 0 and 4 % 2 || ($foo = 1) xor 5 * 4 * 3 * 2 * 1) { // applied |
|
| 48 | // ... |
||
| 49 | } |
||
| 50 | } |
||
| 51 |
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.