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

VisitEvent   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 23.53%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 15
c 1
b 0
f 0
dl 0
loc 34
ccs 4
cts 17
cp 0.2353
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A __invoke() 0 21 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