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

HangmanGoodLetterProposedEvent::deserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

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