Passed
Push — master ( 085587...41d27c )
by Paweł
03:39
created

TownVisitEvent::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
ccs 0
cts 10
cp 0
rs 9.9666
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Event;
6
7
use AardsGerds\Game\Location\Town\Town;
8
use AardsGerds\Game\Location\Town\Visitor;
9
use AardsGerds\Game\Player\Player;
10
use AardsGerds\Game\Player\PlayerAction;
11
use function Lambdish\Phunctional\map;
12
13
abstract class TownVisitEvent extends Event
14
{
15
    public function __construct(
16
        Context $context,
17
        DecisionCollection $decisionCollection,
18
        Player $player,
19
        protected Town $town,
20
    ) {
21
        parent::__construct(
22
            $context,
23
            $decisionCollection,
24
            $player,
25
        );
26
    }
27
28
    public function __invoke(PlayerAction $playerAction): Decision
29
    {
30
        $playerAction->savePlayerState($this->player);
31
        $playerAction->introduce($this->town->getName());
32
        $playerAction->tell((string) $this->context);
33
34
        $visitors = $this->town->getVisitors();
35
        $playerAction->list(map(
36
            static fn(Visitor $visitor): array => [$visitor->getName() => (string) $visitor->getRole()],
37
            $visitors,
38
        ));
39
40
        $playerAction->askForConfirmation('Continue?');
41
42
        // travel
43
        return $playerAction->askForDecision('question', $this->decisionCollection);
44
    }
45
}
46