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

HangmanGameFailedStartingEvent::deserialize()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Hangman\Event;
4
5
use Hangman\Event\Util\HangmanErrorEvent;
6
use MiniGame\Entity\MiniGameId;
7
use MiniGame\Entity\PlayerId;
8
9
class HangmanGameFailedStartingEvent extends HangmanErrorEvent
10
{
11
    /**
12
     * @var string
13
     */
14
    const NAME = 'hangman.starting.failed';
15
16
    /**
17
     * @var string
18
     */
19
    const BAD_STATE = 'alreadyStarted';
20
21
    /**
22
     * @var string
23
     */
24
    const NO_PLAYER = 'noPlayer';
25
26
    /**
27
     * @var string
28
     */
29
    private $reason;
30
31
    /**
32
     * Constructor
33
     *
34
     * @param MiniGameId $gameId
35
     * @param PlayerId   $playerId
36
     * @param string     $reason
37
     */
38 15
    public function __construct(MiniGameId $gameId, PlayerId $playerId = null, $reason = '')
39
    {
40 15
        parent::__construct(self::NAME, $gameId, $playerId);
41 15
        $this->reason = $reason;
42 15
    }
43
44 9
    public function getAsMessage()
45
    {
46 9
        switch ($this->reason) {
47 9
            case self::BAD_STATE:
48 3
                return "You can't start a game that's already started or is over.";
49 6
            case self::NO_PLAYER:
50 3
                return "You can't start a game that has no player.";
51 2
            default:
52 3
                return "Game failed starting for unknown reasons";
53 2
        }
54
    }
55
}
56