Passed
Push — master ( a665f8...0b64a5 )
by Paweł
03:11
created

DialogEvent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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