| Conditions | 19 |
| Paths | 197 |
| Total Lines | 49 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 50.6832 |
| 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 |
||
| 13 | 1 | function update_quality() { |
|
| 14 | 1 | foreach ($this->items as $item) { |
|
| 15 | 1 | if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') { |
|
| 16 | 1 | if ($item->quality > 0) { |
|
| 17 | if ($item->name != 'Sulfuras, Hand of Ragnaros') { |
||
| 18 | 1 | $item->quality = $item->quality - 1; |
|
| 19 | } |
||
| 20 | } |
||
| 21 | } else { |
||
| 22 | if ($item->quality < 50) { |
||
| 23 | $item->quality = $item->quality + 1; |
||
| 24 | if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') { |
||
| 25 | if ($item->sell_in < 11) { |
||
| 26 | if ($item->quality < 50) { |
||
| 27 | $item->quality = $item->quality + 1; |
||
| 28 | } |
||
| 29 | } |
||
| 30 | if ($item->sell_in < 6) { |
||
| 31 | if ($item->quality < 50) { |
||
| 32 | $item->quality = $item->quality + 1; |
||
| 33 | } |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | 1 | if ($item->name != 'Sulfuras, Hand of Ragnaros') { |
|
| 40 | 1 | $item->sell_in = $item->sell_in - 1; |
|
| 41 | } |
||
| 42 | |||
| 43 | 1 | if ($item->sell_in < 0) { |
|
| 44 | 1 | if ($item->name != 'Aged Brie') { |
|
| 45 | 1 | if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') { |
|
| 46 | 1 | if ($item->quality > 0) { |
|
| 47 | if ($item->name != 'Sulfuras, Hand of Ragnaros') { |
||
| 48 | 1 | $item->quality = $item->quality - 1; |
|
| 49 | } |
||
| 50 | } |
||
| 51 | } else { |
||
| 52 | 1 | $item->quality = $item->quality - $item->quality; |
|
| 53 | } |
||
| 54 | } else { |
||
| 55 | if ($item->quality < 50) { |
||
| 56 | 1 | $item->quality = $item->quality + 1; |
|
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 | 1 | } |
|
| 62 | } |
||
| 65 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.