CseExceptions::throwException()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace cse\base;
6
7
use Exception;
8
9
/**
10
 * Class CseException
11
 *
12
 * @package cse\based\extend
13
 */
14
class CseExceptions extends Exception
15
{
16
    protected const DEFAULT_ERROR_MSG = 'Unknown error';
17
18
    /**
19
     * @var array
20
     */
21
    private static $errorsMsg = [];
22
23
    /**
24
     * Get error msg
25
     *
26
     * @param int $code
27
     *
28
     * @return string
29
     */
30
    public static function getErrorMsg(int $code): ?string
31
    {
32
        return static::$errorsMsg[$code] ?? static::DEFAULT_ERROR_MSG;
0 ignored issues
show
Bug introduced by
Since $errorsMsg is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $errorsMsg to at least protected.
Loading history...
33
    }
34
35
    /**
36
     * Throw new exception
37
     *
38
     * @param int $code
39
     * @param string|null $msg
40
     *
41
     * @throws CseExceptions
42
     */
43
    public static function throwException(int $code, ?string $msg = ''): void
44
    {
45
        throw new static(static::getErrorMsg($code) . (empty($msg) ? '' : $msg), $code);
46
    }
47
}