PHP8: use match function

This commit is contained in:
Sunch 2024-08-17 20:12:37 +08:00
parent 1275a4558c
commit f74e6e0638
41 changed files with 300 additions and 574 deletions

View file

@ -7,20 +7,14 @@ abstract class ItemAxe extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_AXE:
return 1;
case GOLDEN_AXE:
return 2;
case STONE_AXE:
return 3;
case IRON_AXE:
return 4;
case DIAMOND_AXE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_AXE => 1,
GOLDEN_AXE => 2,
STONE_AXE => 3,
IRON_AXE => 4,
DIAMOND_AXE => 5,
default => false,
};
}
}

View file

@ -16,20 +16,14 @@ abstract class ItemHoe extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_HOE:
return 1;
case GOLDEN_HOE:
return 2;
case STONE_HOE:
return 3;
case IRON_HOE:
return 4;
case DIAMOND_HOE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_HOE => 1,
GOLDEN_HOE => 2,
STONE_HOE => 3,
IRON_HOE => 4,
DIAMOND_HOE => 5,
default => false,
};
}
}

View file

@ -12,20 +12,14 @@ abstract class ItemPickaxe extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_PICKAXE:
return 1;
case GOLDEN_PICKAXE:
return 2;
case STONE_PICKAXE:
return 3;
case IRON_PICKAXE:
return 4;
case DIAMOND_PICKAXE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_PICKAXE => 1,
GOLDEN_PICKAXE => 2,
STONE_PICKAXE => 3,
IRON_PICKAXE => 4,
DIAMOND_PICKAXE => 5,
default => false,
};
}
}

View file

@ -7,20 +7,14 @@ class ItemShovel extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_SHOVEL:
return 1;
case GOLDEN_SHOVEL:
return 2;
case STONE_SHOVEL:
return 3;
case IRON_SHOVEL:
return 4;
case DIAMOND_SHOVEL:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_SHOVEL => 1,
GOLDEN_SHOVEL => 2,
STONE_SHOVEL => 3,
IRON_SHOVEL => 4,
DIAMOND_SHOVEL => 5,
default => false,
};
}
}

View file

@ -8,20 +8,14 @@ abstract class ItemSword extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_SWORD:
return 1;
case GOLDEN_SWORD:
return 2;
case STONE_SWORD:
return 3;
case IRON_SWORD:
return 4;
case DIAMOND_SWORD:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_SWORD => 1,
GOLDEN_SWORD => 2,
STONE_SWORD => 3,
IRON_SWORD => 4,
DIAMOND_SWORD => 5,
default => false,
};
}
}