Completed
Pull Request — master (#194)
by De Cramer
24:15 queued 02:45
created

PlayerException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 1
b 1
f 0
cc 1
eloc 3
nc 1
nop 4
crap 1
1
<?php
2
3
namespace eXpansion\Framework\Core\Exceptions;
4
5
use Throwable;
6
7
/**
8
 * Class PlayerException, is a special type of extension that needs to be used only to display an error message to a
9
 * player. These exceptions should not be logged but always catched.
10
 *
11
 * @author    de Cramer Oliver<[email protected]>
12
 * @copyright 2017 eXpansion
13
 * @package eXpansion\Framework\Core\Exceptions
14
 */
15
class PlayerException extends ApplicationException
16
{
17
    /** @var string|null */
18
    protected $translatableMessage = null;
19
20
    /**
21
     * PlayerException constructor.
22
     *
23
     * @param string $message
24
     * @param int $code
25
     * @param Throwable|null $previous
26
     * @param null $translatableMessage
27
     */
28 3
    public function __construct($message = "", $code = 0, Throwable $previous = null, $translatableMessage = null)
29
    {
30 3
        parent::__construct($message, $code, $previous);
31 3
        $this->translatableMessage = $translatableMessage;
32 3
    }
33
34
    /**
35
     * Get error message to translate and send to users.
36
     *
37
     * @return string
38
     */
39
    public function getTranslatableMessage()
40
    {
41
        return is_null($this->translatableMessage) ? $this->message : $this->translatableMessage;
42
    }
43
}