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

PlayerIO::section()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
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