Completed
Push — master ( 5931ad...7b9134 )
by Rémi
03:04
created

cannotLeaveGameUserIsNotIn()   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 1
crap 1
1
<?php
2
3
namespace MessageApp\Parser\Exception;
4
5
use MessageApp\Exception\MessageAppException;
6
use MessageApp\User\ApplicationUser;
7
8
class MessageParserException extends MessageAppException
9
{
10
    const JOIN_MULTIPLE_USERS = 'JOIN.MULTIPLE-USERS';
11
    const JOIN_UNREGISTERED_USER = 'JOIN.UNREGISTERED-USERS';
12
    const JOIN_NO_GAME = 'JOIN.NO-GAME';
13
    const JOIN_YOURSELF = 'JOIN.YOURSELF';
14
    const JOIN_GAME_RUNNING = 'JOIN.GAME-RUNNING';
15
    const START_NOT_IN = 'START.NOT-IN';
16
    const LEAVE_NOT_IN = 'LEAVE.NOT-IN';
17
    const CREATE_MULTIPLE = 'CREATE.MULTIPLE';
18
    const GAME_NOT_FOUND = 'GAME-NOT-FOUND';
19
    const INVALID_USER = 'INVALID-USER';
20
    const PARSE_ERROR = 'PARSE-ERROR';
21
22
    /**
23
     * @var string
24
     */
25
    private $codeName;
26
27
    /**
28
     * Constructor
29
     *
30
     * @param ApplicationUser $user
31
     * @param string          $codeName
32
     * @param string          $message
33
     * @param int             $code
34
     * @param \Exception      $previous
35
     */
36 39
    public function __construct(
37
        ApplicationUser $user = null,
38
        $codeName = null,
39
        $message = '',
40
        $code = 0,
41
        \Exception $previous = null
42
    ) {
43 39
        parent::__construct($user, $message, $code, $previous);
44 39
        $this->codeName = $codeName;
45 39
    }
46
47
    /**
48
     * @return string
49
     */
50 33
    public function getCodeName()
51
    {
52 33
        return $this->codeName;
53
    }
54
55
    /**
56
     * @param ApplicationUser $user
57
     * @return MessageParserException
58
     */
59 3
    public static function cannotJoinMultipleUsers(ApplicationUser $user)
60
    {
61 3
        return new self($user, self::JOIN_MULTIPLE_USERS, 'You have to provide one (and only one) user to join!');
62
    }
63
64
    /**
65
     * @param ApplicationUser $user
66
     * @return MessageParserException
67
     */
68 3
    public static function cannotJoinUnregisteredUser(ApplicationUser $user)
69
    {
70 3
        return new self($user, self::JOIN_UNREGISTERED_USER, 'You cannot join a user who is not registered!');
71
    }
72
73
    /**
74
     * @param ApplicationUser $user
75
     * @return MessageParserException
76
     */
77 3
    public static function cannotJoinUserWithoutAGame(ApplicationUser $user)
78
    {
79 3
        return new self($user, self::JOIN_NO_GAME, 'You cannot join a player with no game!');
80
    }
81
82
    /**
83
     * @param ApplicationUser $user
84
     * @return MessageParserException
85
     */
86 3
    public static function cannotJoinYourself(ApplicationUser $user)
87
    {
88 3
        return new self($user, self::JOIN_YOURSELF, 'You cannot join yourself!');
89
    }
90
91
    /**
92
     * @param ApplicationUser $user
93
     * @return MessageParserException
94
     */
95 3
    public static function cannotJoinIfGameAlreadyRunning(ApplicationUser $user)
96
    {
97 3
        return new self($user, self::JOIN_GAME_RUNNING, 'You already have a game running!');
98
    }
99
100
    /**
101
     * @param ApplicationUser $user
102
     * @return MessageParserException
103
     */
104 3
    public static function cannotParseMessage(ApplicationUser $user)
105
    {
106 3
        return new self($user, self::PARSE_ERROR, 'Could not parse message!');
107
    }
108
109
    /**
110
     * @param ApplicationUser $user
111
     * @return MessageParserException
112
     */
113 3
    public static function cannotStartGameUserIsNotIn(ApplicationUser $user)
114
    {
115 3
        return new self($user, self::START_NOT_IN, 'You cannot start a game you are not in!');
116
    }
117
118
    /**
119
     * @param ApplicationUser $user
120
     * @return MessageParserException
121
     */
122 3
    public static function cannotLeaveGameUserIsNotIn(ApplicationUser $user)
123
    {
124 3
        return new self($user, self::LEAVE_NOT_IN, 'You cannot leave a game you are not in!');
125
    }
126
127
    /**
128
     * @param ApplicationUser $user
129
     * @return MessageParserException
130
     */
131 3
    public static function cannotFindGameForUser(ApplicationUser $user)
132
    {
133 3
        return new self(
134 2
            $user,
135 3
            self::GAME_NOT_FOUND,
136 1
            'The game or associated player was not found. Try starting/joining a game first.'
137 2
        );
138
    }
139
140
    /**
141
     * @param ApplicationUser $user
142
     * @return MessageParserException
143
     */
144 3
    public static function cannotCreateMultipleGames(ApplicationUser $user)
145
    {
146 3
        return new self($user, self::CREATE_MULTIPLE, 'You already have a game running!');
147
    }
148
149
    /**
150
     * @param ApplicationUser $user
151
     * @return MessageParserException
152
     */
153 6
    public static function invalidUser(ApplicationUser $user)
154
    {
155 6
        return new self($user, self::INVALID_USER, 'User is not valid!');
156
    }
157
}
158