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

HangmanGameLostEvent   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 2 Features 2
Metric Value
wmc 6
c 6
b 2
f 2
lcom 1
cbo 3
dl 0
loc 75
ccs 22
cts 22
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getWord() 0 4 1
A getAsMessage() 0 4 1
A getSolution() 0 4 1
A serialize() 0 9 1
A deserialize() 0 8 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