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

DialogEvent   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 28
ccs 4
cts 12
cp 0.3333
rs 10

3 Methods

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