| Conditions | 16 |
| Paths | 31 |
| Total Lines | 57 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 20 | public function updateItemQuality(Item $item): Item |
||
| 21 | { |
||
| 22 | $item = clone $item; |
||
| 23 | |||
| 24 | switch ($item->name) { |
||
| 25 | case 'Aged Brie': |
||
| 26 | if ($item->quality < 50) { |
||
| 27 | $item->quality = $item->quality + 1; |
||
| 28 | } |
||
| 29 | $item->sell_in = $item->sell_in - 1; |
||
| 30 | |||
| 31 | if ($item->sell_in < 0 && $item->quality < 50) { |
||
| 32 | $item->quality = $item->quality + 1; |
||
| 33 | } |
||
| 34 | |||
| 35 | return $item; |
||
| 36 | case 'Backstage passes to a TAFKAL80ETC concert': |
||
| 37 | if ($item->quality < 50) { |
||
| 38 | $item->quality = $item->quality + 1; |
||
| 39 | |||
| 40 | if ($item->sell_in < 11) { |
||
| 41 | if ($item->quality < 50) { |
||
| 42 | $item->quality = $item->quality + 1; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | if ($item->sell_in < 6) { |
||
| 47 | if ($item->quality < 50) { |
||
| 48 | $item->quality = $item->quality + 1; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } |
||
| 52 | $item->sell_in = $item->sell_in - 1; |
||
| 53 | |||
| 54 | if ($item->sell_in < 0) { |
||
| 55 | $item->quality = 0; |
||
| 56 | } |
||
| 57 | |||
| 58 | return $item; |
||
| 59 | case 'Sulfuras, Hand of Ragnaros': |
||
| 60 | break; |
||
| 61 | default: |
||
| 62 | if ($item->quality > 0) { |
||
| 63 | $item->quality = $item->quality - 1; |
||
| 64 | } |
||
| 65 | $item->sell_in = $item->sell_in - 1; |
||
| 66 | |||
| 67 | if ($item->sell_in < 0) { |
||
| 68 | if ($item->quality > 0) { |
||
| 69 | $item->quality = $item->quality - 1; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | return $item; |
||
| 74 | } |
||
| 75 | |||
| 76 | return $item; |
||
| 77 | } |
||
| 79 |