Completed
Push — master ( 719dbc...a8fbe3 )
by Rémi
03:51
created

HangmanBadLetterProposedEvent::deserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 12
ccs 10
cts 10
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Hangman\Event;
4
5
use Hangman\Event\Util\HangmanResultEvent;
6
use Hangman\Result\HangmanBadProposition;
7
use MiniGame\Entity\MiniGameId;
8
use MiniGame\Entity\PlayerId;
9
10
class HangmanBadLetterProposedEvent extends HangmanResultEvent implements HangmanBadProposition
11
{
12
    /**
13
     * @var string
14
     */
15
    const NAME = 'hangman.letter.bad';
16
17
    /**
18
     * @var string
19
     */
20
    private $letter;
21
22
    /**
23
     * @var int
24
     */
25
    private $livesLost;
26
27
    /**
28
     * @var string
29
     */
30
    private $wordSoFar;
31
32
    /**
33
     * Constructor
34
     *
35
     * @param MiniGameId $gameId
36
     * @param PlayerId   $playerId
37
     * @param string     $letter
38
     * @param array      $playedLetters
39
     * @param int        $livesLost
40
     * @param int        $remainingLives
41
     * @param string     $wordSoFar
42
     */
43 18
    public function __construct(
44
        MiniGameId $gameId,
45
        PlayerId $playerId,
46
        $letter,
47
        array $playedLetters,
48
        $livesLost,
49
        $remainingLives,
50
        $wordSoFar
51
    ) {
52 18
        parent::__construct(self::NAME, $gameId, $playerId, $playedLetters, $remainingLives);
53 18
        $this->letter = $letter;
54 18
        $this->livesLost = $livesLost;
55 18
        $this->wordSoFar = $wordSoFar;
56 18
    }
57
58
    /**
59
     * @return string
60
     */
61 15
    public function getLetter()
62
    {
63 15
        return $this->letter;
64
    }
65
66
    /**
67
     * @return int
68
     */
69 15
    public function getLivesLost()
70
    {
71 15
        return $this->livesLost;
72
    }
73
74
    /**
75
     * @return string
76
     */
77 3
    public function getWordSoFar()
78
    {
79 3
        return $this->wordSoFar;
80
    }
81
82
    /**
83
     * @return string
84
     */
85 6
    public function getFeedback()
86
    {
87 6
        return $this->wordSoFar;
88
    }
89
90
    /**
91
     * @return string
92
     */
93 3
    public function getAsMessage()
94
    {
95 3
        return sprintf(
96 3
            'Too bad... %s (letters played: %s) - Remaining chances: %d',
97 3
            $this->getWordSoFar(),
98 3
            implode(', ', $this->getPlayedLetters()),
99 3
            $this->getRemainingLives()
100 2
        );
101
    }
102
}
103