Completed
Push — master ( 3a0fd5...719dbc )
by Rémi
02:36
created

HangmanGameLostEvent::getPlayerId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Hangman\Event;
4
5
use Broadway\Serializer\SerializableInterface;
6
use Hangman\Event\Util\HangmanBasicResultEvent;
7
use MiniGame\Entity\MiniGameId;
8
use MiniGame\Entity\PlayerId;
9
use MiniGame\Result\AllPlayersResult;
10
use MiniGame\Result\GameLost;
11
12
class HangmanGameLostEvent extends HangmanBasicResultEvent implements AllPlayersResult, SerializableInterface, GameLost
13
{
14
    /**
15
     * @var string
16
     */
17
    const NAME = 'hangman.lost';
18
19
    /**
20
     * @var string
21
     */
22
    private $word;
23
24
    /**
25
     * Constructor
26
     *
27
     * @param MiniGameId $gameId
28
     * @param PlayerId   $playerId
29
     * @param string     $word
30
     */
31 12
    public function __construct(MiniGameId $gameId, PlayerId $playerId, $word)
32
    {
33 12
        parent::__construct(self::NAME, $gameId, $playerId);
34 12
        $this->word = $word;
35 12
    }
36
37
    /**
38
     * @return string
39
     */
40 6
    public function getWord()
41
    {
42 6
        return $this->word;
43
    }
44
45
    /**
46
     * @return string
47
     */
48 3
    public function getAsMessage()
49
    {
50 3
        return 'Game lost';
51
    }
52
53
    /**
54
     * @return string
55
     */
56 3
    public function getSolution()
57
    {
58 3
        return $this->word;
59
    }
60
61
    /**
62
     * @return array
63
     */
64 3
    public function serialize()
65
    {
66
        return [
67 3
            'name' => self::NAME,
68 3
            'gameId' => (string) $this->getGameId(),
69 3
            'playerId' => (string) $this->getPlayerId(),
70 3
            'word' => $this->word
71 2
        ];
72
    }
73
74
    /**
75
     * @param  array $data
76
     * @return HangmanGameLostEvent
77
     */
78 3
    public static function deserialize(array $data)
79
    {
80 3
        return new self(
81 3
            MiniGameId::create($data['gameId']),
82 3
            PlayerId::create($data['playerId']),
83 3
            $data['word']
84 2
        );
85
    }
86
}
87