Passed
Push — master ( 9ad4f6...7fb37f )
by Jakub
01:42
created

Weapon   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 8
eloc 30
dl 0
loc 45
ccs 15
cts 18
cp 0.8333
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isRanged() 0 2 1
A getAllowedTypes() 0 2 1
A getDamageStat() 0 11 5
A configureOptions() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
use Nexendrie\Utils\Constants;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
/**
10
 * Weapon
11
 *
12
 * @author Jakub Konečný
13
 * @property-read bool $ranged
14
 * @property-read string $damageStat
15
 */
16 1
class Weapon extends Equipment {
17
  public const TYPE_SWORD = "sword";
18
  public const TYPE_AXE = "axe";
19
  public const TYPE_CLUB = "club";
20
  public const TYPE_DAGGER = "dagger";
21
  public const TYPE_SPEAR = "spear";
22
  public const TYPE_STAFF = "staff";
23
  public const TYPE_BOW = "bow";
24
  public const TYPE_CROSSBOW = "crossbow";
25
  public const TYPE_THROWING_KNIFE = "throwing knife";
26
  public const MELEE_TYPES = [
27
    self::TYPE_SWORD, self::TYPE_AXE, self::TYPE_CLUB, self::TYPE_DAGGER, self::TYPE_SPEAR,
28
  ];
29
  public const RANGED_TYPES = [
30
    self::TYPE_STAFF, self::TYPE_BOW, self::TYPE_CROSSBOW, self::TYPE_THROWING_KNIFE,
31
  ];
32
  
33
  public function isRanged(): bool {
34 1
    return in_array($this->type, static::RANGED_TYPES, true);
35
  }
36
37
  public function getDamageStat(): string {
38 1
    switch($this->type) {
39 1
      case static::TYPE_STAFF:
40
        return Character::STAT_INTELLIGENCE;
41 1
      case static::TYPE_CLUB:
42
        return Character::STAT_CONSTITUTION;
43 1
      case static::TYPE_BOW:
44 1
      case static::TYPE_THROWING_KNIFE:
45
        return Character::STAT_DEXTERITY;
46
      default:
47 1
        return Character::STAT_STRENGTH;
48
    }
49
  }
50
  
51
  protected function configureOptions(OptionsResolver $resolver): void {
52 1
    parent::configureOptions($resolver);
53 1
    $resolver->setAllowedTypes("type", "string");
54 1
    $resolver->setAllowedValues("type", function(string $value) {
55 1
      return in_array($value, $this->getAllowedTypes(), true);
56 1
    });
57 1
  }
58
  
59
  protected function getAllowedTypes(): array {
60 1
    return Constants::getConstantsValues(static::class, "TYPE_");
61
  }
62
}
63
?>