Completed
Push — master ( 843ccd...b2206c )
by Jakub
02:38
created

Weapon::getAllowedTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 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
 */
15 1
class Weapon extends Equipment {
16
  public const TYPE_SWORD = "sword";
17
  public const TYPE_AXE = "axe";
18
  public const TYPE_CLUB = "club";
19
  public const TYPE_DAGGER = "dagger";
20
  public const TYPE_SPEAR = "spear";
21
  public const TYPE_STAFF = "staff";
22
  public const TYPE_BOW = "bow";
23
  public const TYPE_CROSSBOW = "crossbow";
24
  public const TYPE_THROWING_KNIFE = "throwing knife";
25
  
26
  public function isRanged(): bool {
27 1
    return in_array($this->type, [
28 1
      static::TYPE_STAFF, static::TYPE_BOW, static::TYPE_CROSSBOW, static::TYPE_THROWING_KNIFE,
29 1
    ], true);
30
  }
31
  
32
  protected function configureOptions(OptionsResolver $resolver): void {
33 1
    parent::configureOptions($resolver);
34 1
    $resolver->setAllowedTypes("type", ["string"]);
35 1
    $resolver->setAllowedValues("type", function(?string $value) {
36 1
      return is_null($value) OR in_array($value, $this->getAllowedTypes(), true);
37 1
    });
38 1
  }
39
  
40
  protected function getAllowedTypes(): array {
41 1
    return Constants::getConstantsValues(static::class, "TYPE_");
42
  }
43
}
44
?>