Passed
Push — master ( 98f021...0d9edd )
by Jakub
01:48
created

Weapon::getDamageStat()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 11
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5.9256

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 11
ccs 6
cts 9
cp 0.6667
rs 9.6111
c 0
b 0
f 0
cc 5
nc 5
nop 0
crap 5.9256
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
  
27
  public function isRanged(): bool {
28 1
    return in_array($this->type, [
29 1
      static::TYPE_STAFF, static::TYPE_BOW, static::TYPE_CROSSBOW, static::TYPE_THROWING_KNIFE,
30 1
    ], true);
31
  }
32
33
  public function getDamageStat(): string {
34 1
    switch($this->type) {
35 1
      case static::TYPE_STAFF:
36
        return Character::STAT_INTELLIGENCE;
37 1
      case static::TYPE_CLUB:
38
        return Character::STAT_CONSTITUTION;
39 1
      case static::TYPE_BOW:
40 1
      case static::TYPE_THROWING_KNIFE:
41
        return Character::STAT_DEXTERITY;
42
      default:
43 1
        return Character::STAT_STRENGTH;
44
    }
45
  }
46
  
47
  protected function configureOptions(OptionsResolver $resolver): void {
48 1
    parent::configureOptions($resolver);
49 1
    $resolver->setAllowedTypes("type", "string");
50 1
    $resolver->setAllowedValues("type", function(string $value) {
51 1
      return in_array($value, $this->getAllowedTypes(), true);
52 1
    });
53 1
  }
54
  
55
  protected function getAllowedTypes(): array {
56 1
    return Constants::getConstantsValues(static::class, "TYPE_");
57
  }
58
}
59
?>