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

TownVisitEvent   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 1
b 0
f 0
dl 0
loc 31
ccs 0
cts 14
cp 0
rs 10

2 Methods

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