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

PlayerIO::list()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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
        $this->clearOutput();
29
        return $this->io->choice($question, $decisions->getItems());
30
    }
31
32
    public function askForChoice(string $question, array $choices): mixed
33
    {
34
        return $this->io->choice($question, $choices);
35
    }
36
37
    public function askForInformation(string $question): string
38
    {
39
        return $this->io->ask($question);
40
    }
41
42
    public function askForConfirmation(string $question): bool
43
    {
44
        return $this->io->confirm($question);
45
    }
46
47
    public function tell(string|array $message): void
48
    {
49
        sleep(1);
50
        $this->io->text($message);
51
    }
52
53
    public function list(array $items): void
54
    {
55
        sleep(1);
56
        $this->io->definitionList(...$items);
57
    }
58
59
    public function introduce(string $message): void
60
    {
61
        sleep(1);
62
        $this->io->title($message);
63
    }
64
65
    public function note(string $message): void
66
    {
67
        $this->io->note($message);
68
    }
69
70
    private function clearOutput(): void
71
    {
72
        $this->io->write("\033\143");
73
    }
74
}
75