Lines 100.00% 13 / 13
Methods 100.00% 5 / 5
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 7 / 7 100.00% 1 / 1 7
 target 100.00% 1 / 1 100.00% 1 / 1 1
 with 100.00% 1 / 1 100.00% 1 / 1 1
 at 100.00% 3 / 3 100.00% 1 / 1 2
 toMessage 100.00% 1 / 1 100.00% 1 / 1 1
14final readonly class AttackMonsterCommand implements Attack
15{
16    private string $code;
17
18    /** @throws InvalidArgumentException */
19    public function __construct(
20        private AreaId $area,
21        private SkillSlot $skill,
22        private MonsterSpawnId $monster,
23    ) {
24        $this->code = match ($skill) {
25            SkillSlot::AutoAttack => 'aa',
26            SkillSlot::First => 'a1',
27            SkillSlot::Second => 'a2',
28            SkillSlot::Third => 'a3',
29            SkillSlot::Fourth => 'a4',
30            SkillSlot::Potion => throw new InvalidArgumentException('A potion is not an attack.'),
31        };
32    }
33
34    #[Override]
35    public function target(): MonsterSpawnId
36    {
37        return $this->monster;
38    }
39
40    #[Override]
41    public function with(SkillSlot $skill): static
42    {
43        return new static($this->area, $skill, $this->monster);
44    }
45
46    #[Override]
47    public function at(Targetable $target): static
48    {
49        if (!$target instanceof MonsterSpawnId) {
50            throw new InvalidArgumentException('A monster attack can only aim at a monster.');
51        }
52
53        return new static($this->area, $this->skill, $target);
54    }
55
56    #[Override]
57    public function toMessage(): string
58    {
59        return "%xt%zm%gar%{$this->area}%0%{$this->code}>m:{$this->monster}%wvz%";
60    }
61}