| Conditions | 15 |
| Paths | 11 |
| Total Lines | 50 |
| Lines | 28 |
| Ratio | 56 % |
| 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 |
||
| 25 | public function event(BlockBreakEvent $event): void |
||
| 26 | { |
||
| 27 | $block = $event->getBlock(); |
||
| 28 | $inventory = $event->getPlayer()->getInventory(); |
||
| 29 | if (DefaultConfig::isDev() || $block->getLevel()->getName() !== DefaultConfig::getStageLevelName() || TheEndGameEvent::isFinish()) { |
||
| 30 | return; |
||
| 31 | } |
||
| 32 | if ($block->getToolType() !== $inventory->getItemInHand()->getBlockToolType() && !DefaultConfig::isDev()) { |
||
|
|
|||
| 33 | $event->setCancelled(); |
||
| 34 | |||
| 35 | return; |
||
| 36 | } |
||
| 37 | $event->setDrops([]); |
||
| 38 | switch ($block->getId()) { |
||
| 39 | View Code Duplication | case Block::MELON_BLOCK: |
|
| 40 | $inventory->addItem(Item::get(Item::MELON, 0, 16)); |
||
| 41 | TheMix::getInstance()->getScheduler()->scheduleDelayedTask(new BlockReGeneratorTask($block), 10 * 20); |
||
| 42 | break; |
||
| 43 | View Code Duplication | case Block::WOOD: |
|
| 44 | $inventory->addItem(Item::get(Item::WOODEN_PLANKS, 0, 4)); |
||
| 45 | TheMix::getInstance()->getScheduler()->scheduleDelayedTask(new BlockReGeneratorTask($block), 15 * 20); |
||
| 46 | break; |
||
| 47 | View Code Duplication | case Block::DIAMOND_ORE: |
|
| 48 | $inventory->addItem(Item::get(Item::DIAMOND)); |
||
| 49 | TheMix::getInstance()->getScheduler()->scheduleDelayedTask(new BlockReGeneratorTask($block), 60 * 20); |
||
| 50 | break; |
||
| 51 | View Code Duplication | case Block::EMERALD_ORE: |
|
| 52 | $inventory->addItem(Item::get(Item::EMERALD, 0, mt_rand(1, 3))); |
||
| 53 | TheMix::getInstance()->getScheduler()->scheduleDelayedTask(new BlockReGeneratorTask($block), 60 * 20); |
||
| 54 | break; |
||
| 55 | View Code Duplication | case Block::COAL_ORE: |
|
| 56 | $inventory->addItem(Item::get(Item::COAL)); |
||
| 57 | TheMix::getInstance()->getScheduler()->scheduleDelayedTask(new BlockReGeneratorTask($block), 15 * 20); |
||
| 58 | break; |
||
| 59 | View Code Duplication | case Block::IRON_ORE: |
|
| 60 | $inventory->addItem(Item::get(Item::IRON_INGOT)); |
||
| 61 | TheMix::getInstance()->getScheduler()->scheduleDelayedTask(new BlockReGeneratorTask($block), 20 * 20); |
||
| 62 | break; |
||
| 63 | View Code Duplication | case Block::GOLD_ORE: |
|
| 64 | $inventory->addItem(Item::get(Item::GOLD_INGOT)); |
||
| 65 | TheMix::getInstance()->getScheduler()->scheduleDelayedTask(new BlockReGeneratorTask($block), 30 * 20); |
||
| 66 | break; |
||
| 67 | default: |
||
| 68 | if ($event->getPlayer()->getLevel()->getName() === DefaultConfig::getStageLevelName() && DefaultConfig::isDev() === false) { |
||
| 69 | $event->setCancelled(); |
||
| 70 | |||
| 71 | return; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.