Passed
Push — master ( d3b4be...e1d27c )
by Paweł
03:26
created

VisitEvent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 8
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Event;
6
7
use AardsGerds\Game\Location\Location;
8
use AardsGerds\Game\Location\Visitor;
9
use AardsGerds\Game\Player\Player;
10
use AardsGerds\Game\Player\PlayerAction;
11
use function Lambdish\Phunctional\map;
12
13
abstract class VisitEvent extends Event
14
{
15 1
    public function __construct(
16
        Context $context,
17
        DecisionCollection $decisionCollection,
18
        protected Location $location,
19
    ) {
20 1
        parent::__construct(
21 1
            $context,
22
            $decisionCollection,
23
        );
24 1
    }
25
26
    public function __invoke(Player $player, PlayerAction $playerAction): Decision
27
    {
28
        $player->setCheckpoint($this);
29
        $playerAction->savePlayerState($player);
30
31
        $playerAction->introduce($this->location->getName());
32
        $playerAction->tell((string) $this->context);
33
34
        $visitors = $this->location->getVisitors();
35
        $playerAction->list(map(
36
            static fn(Visitor $visitor): array => [$visitor->getName() => (string) $visitor->getRole()],
37
            $visitors,
38
        ));
39
40
        $choice = $playerAction->askForChoice(
0 ignored issues
show
Unused Code introduced by
The assignment to $choice is dead and can be removed.
Loading history...
41
            'Where do you want to go?',
42
            array_merge($visitors->getItems(), ['Leave this place']),
43
        );
44
45
        // travel
46
        return $playerAction->askForDecision('question', $this->decisionCollection);
47
    }
48
}
49