Lines 100.00% 11 / 11
Methods 100.00% 3 / 3
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 describe 100.00% 3 / 3 100.00% 1 / 1 2
 play 100.00% 7 / 7 100.00% 1 / 1 1
15final readonly class FightFor implements Action
16{
17    public function __construct(
18        public MapSpot $spot,
19        public ?MonsterName $monster,
20        public Duration $time,
21    ) {}
22
23    #[Override]
24    public function describe(): string
25    {
26        $who = $this->monster === null ? '' : " {$this->monster->value}";
27        $minutes = (int) $this->time->getTotalMinutes();
28
29        return "Fight{$who} in {$this->spot->cell->value} for {$minutes} min";
30    }
31
32    #[Override]
33    public function play(StepScript $bot): Generator
34    {
35        $deadline = $bot->now()->plus($this->time);
36        yield from $bot->kill(
37            $this->spot,
38            $bot->attackIn($this->spot->cell, $this->monster),
39            static fn(): bool => !$bot->now()->before($deadline),
40        );
41
42        return null;
43    }
44}