InspectorSettingsException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 33
rs 10
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
/** @psalm-consistent-constructor */
20
abstract class InspectorSettingsException extends \Exception
21
{
22
    public const ERROR_NONE = 0;
23
24
    /** @var array<int, string> */
25
    protected const ERRORS = [
26
        self::ERROR_NONE => '',
27
    ];
28
29
    /**
30
     * @param string $message
31
     * @param int $code
32
     * @param Throwable|null $previous
33
     */
34
    public function __construct($message = "", $code = 0, Throwable $previous = null)
35
    {
36
        parent::__construct($message, $code, $previous);
37
    }
38
39
    /** @return array<int, string> */
40
    public static function getErrors(): array
41
    {
42
        /** @var array<int, string> */
43
        return static::ERRORS;
44
    }
45
46
    /** @return static */
47
    public static function create(int $error_no): InspectorSettingsException
48
    {
49
        if (!isset(static::ERRORS[$error_no])) {
50
            throw new LogicException('wrong creation of CommandSettingException');
51
        }
52
        return new static(static::getErrors()[$error_no], $error_no);
53
    }
54
}
55