Passed
Push — master ( f6bfbf...de5018 )
by Shinji
02:30 queued 51s
created

InspectorSettingsException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getErrors() 0 4 1
A __construct() 0 3 1
A create() 0 6 2
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpProfiler\Inspector\Settings;
15
16
use LogicException;
17
use Throwable;
18
19
/**
20
 * @psalm-consistent-constructor
21
 */
22
abstract class InspectorSettingsException extends \Exception
23
{
24
    public const ERROR_NONE = 0;
25
26
    /** @var array<int, string> */
27
    protected const ERRORS = [
28
        self::ERROR_NONE => '',
29
    ];
30
31
    /**
32
     * @param string $message
33
     * @param int $code
34
     * @param Throwable|null $previous
35
     */
36
    public function __construct($message = "", $code = 0, Throwable $previous = null)
37
    {
38
        parent::__construct($message, $code, $previous);
39
    }
40
41
    /**
42
     * @return array<int, string>
43
     */
44
    public static function getErrors(): array
45
    {
46
        /** @var array<int, string> */
47
        return static::ERRORS;
48
    }
49
50
    /**
51
     * @param int $error_no
52
     * @return static
53
     */
54
    public static function create(int $error_no): InspectorSettingsException
55
    {
56
        if (!isset(static::ERRORS[$error_no])) {
57
            throw new LogicException('wrong creation of CommandSettingException');
58
        }
59
        return new static(static::getErrors()[$error_no], $error_no);
60
    }
61
}
62