Passed
Push — master ( 888025...8927c7 )
by Paweł
03:33
created

PlayerIO   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
c 2
b 0
f 0
dl 0
loc 66
ccs 0
cts 36
cp 0
rs 10
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A savePlayerState() 0 3 1
A __construct() 0 4 1
A tell() 0 4 1
A askForDecision() 0 3 1
A askForChoice() 0 3 1
A note() 0 3 1
A section() 0 4 1
A clearOutput() 0 3 1
A introduce() 0 6 1
A list() 0 4 1
A askForInformation() 0 3 1
A askForConfirmation() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Infrastructure\Cli;
6
7
use AardsGerds\Game\Event\Decision;
8
use AardsGerds\Game\Event\DecisionCollection;
9
use AardsGerds\Game\Infrastructure\Persistence\PlayerState;
10
use AardsGerds\Game\Player\Player;
11
use AardsGerds\Game\Player\PlayerAction;
12
use Symfony\Component\Console\Style\SymfonyStyle;
13
14
final class PlayerIO implements PlayerAction
15
{
16
    public function __construct(
17
        private SymfonyStyle $io,
18
        private PlayerState $playerState,
19
    ) {}
20
21
    public function savePlayerState(Player $player): void
22
    {
23
        $this->playerState->save($player);
24
    }
25
26
    public function askForDecision(string $question, DecisionCollection $decisions): Decision
27
    {
28
        return $this->io->choice($question, $decisions->getItems());
29
    }
30
31
    public function askForChoice(string $question, array $choices): mixed
32
    {
33
        return $this->io->choice($question, $choices);
34
    }
35
36
    public function askForInformation(string $question): string
37
    {
38
        return $this->io->ask($question);
39
    }
40
41
    public function askForConfirmation(string $question): bool
42
    {
43
        return $this->io->confirm($question);
44
    }
45
46
    public function tell(string|array $message): void
47
    {
48
        sleep(1);
49
        $this->io->text($message);
50
    }
51
52
    public function list(array $items): void
53
    {
54
        sleep(1);
55
        $this->io->definitionList(...$items);
56
    }
57
58
    public function introduce(string $message): void
59
    {
60
        sleep(1);
61
        $this->clearOutput();
62
        $this->io->title($message);
63
        sleep(1);
64
    }
65
66
    public function section(string $message): void
67
    {
68
        sleep(1);
69
        $this->io->section($message);
70
    }
71
72
    public function note(string $message): void
73
    {
74
        $this->io->note($message);
75
    }
76
77
    private function clearOutput(): void
78
    {
79
        $this->io->write("\033\143");
80
    }
81
}
82