Passed
Push — master ( 8927c7...af53cd )
by Paweł
03:06
created

VisitEvent::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Event;
6
7
use AardsGerds\Game\Event\Decision\Decision;
8
use AardsGerds\Game\Event\Decision\DecisionCollection;
9
use AardsGerds\Game\Player\Player;
10
use AardsGerds\Game\Player\PlayerAction;
11
12
abstract class VisitEvent extends Event
13
{
14 1
    public function __construct(
15
        Context $context,
16
        DecisionCollection $decisionCollection,
17
    ) {
18 1
        parent::__construct(
19 1
            $context,
20
            $decisionCollection,
21
        );
22 1
    }
23
24
    public function __invoke(Player $player, PlayerAction $playerAction): Decision
25
    {
26
        $player->setCheckpoint($this);
27
        $playerAction->savePlayerState($player);
28
29
        $playerAction->introduce((string) $this->context->getLocation());
30
        $playerAction->tell((string) $this->context);
31
32
        return $playerAction->askForDecision('Where do you want to go?', $this->decisionCollection);
33
    }
34
35
    public function getContext(): Context
36
    {
37
        return $this->context;
38
    }
39
}
40