Weapon::isRanged()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 1
cts 1
cp 1
cc 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
 * @property-read string $damageStat
15
 */
16 1
class Weapon extends Equipment
17
{
18
    public const TYPE_SWORD = "sword";
19
    public const TYPE_AXE = "axe";
20
    public const TYPE_CLUB = "club";
21
    public const TYPE_DAGGER = "dagger";
22
    public const TYPE_SPEAR = "spear";
23
    public const TYPE_STAFF = "staff";
24
    public const TYPE_BOW = "bow";
25
    public const TYPE_CROSSBOW = "crossbow";
26
    public const TYPE_THROWING_KNIFE = "throwing knife";
27
    public const TYPE_INSTRUMENT = "instrument";
28
    public const MELEE_TYPES = [
29
        self::TYPE_SWORD, self::TYPE_AXE, self::TYPE_CLUB, self::TYPE_DAGGER, self::TYPE_SPEAR,
30
    ];
31
    public const RANGED_TYPES = [
32
        self::TYPE_STAFF, self::TYPE_BOW, self::TYPE_CROSSBOW, self::TYPE_THROWING_KNIFE, self::TYPE_INSTRUMENT,
33
    ];
34
35
    protected function isRanged(): bool
36
    {
37 1
        return in_array($this->type, static::RANGED_TYPES, true);
38
    }
39
40
    protected function getDamageStat(): string
41
    {
42 1
        return match ($this->type) {
43 1
            static::TYPE_STAFF => Character::STAT_INTELLIGENCE,
44 1
            static::TYPE_CLUB => Character::STAT_CONSTITUTION,
45 1
            static::TYPE_BOW, static::TYPE_THROWING_KNIFE => Character::STAT_DEXTERITY,
46 1
            static::TYPE_INSTRUMENT => Character::STAT_CHARISMA,
47 1
            default => Character::STAT_STRENGTH,
48
        };
49
    }
50
51
    protected function configureOptions(OptionsResolver $resolver): void
52
    {
53 1
        parent::configureOptions($resolver);
54 1
        $resolver->setAllowedTypes("type", "string");
55 1
        $resolver->setAllowedValues("type", function (string $value): bool {
56 1
            return in_array($value, $this->getAllowedTypes(), true);
57 1
        });
58 1
    }
59
60
    protected function getAllowedTypes(): array
61
    {
62 1
        return Constants::getConstantsValues(static::class, "TYPE_");
63
    }
64
}
65