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

PlayerException::getTranslatableMessage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 1
f 0
ccs 0
cts 2
cp 0
cc 2
eloc 2
nc 2
nop 0
crap 6
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
}