Passed
Pull Request — master (#391)
by Arman
03:09
created

BaseException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Quantum PHP Framework
7
 *
8
 * An open source software development framework for PHP
9
 *
10
 * @package Quantum
11
 * @author Arman Ag. <[email protected]>
12
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
13
 * @link http://quantum.softberg.org/
14
 * @since 3.0.0
15
 */
16
17
namespace Quantum\App\Exceptions;
18
19
use Quantum\App\Enums\ExceptionMessages;
20
use Exception;
21
22
/**
23
 * Class BaseException
24
 * @package Quantum\App
25
 */
26
abstract class BaseException extends Exception
27
{
28
29
    /**
30
     * @param string $message
31
     * @param int $code
32
     */
33
    final public function __construct(string $message = "", int $code = 0)
34
    {
35
        parent::__construct($message, $code);
36
    }
37
38
    /**
39
     * @param string $methodName
40
     * @param string $className
41
     * @return static
42
     */
43
    public static function methodNotSupported(string $methodName, string $className)
44
    {
45
        return new static(
46
            _message(ExceptionMessages::METHOD_NOT_SUPPORTED, [$methodName, $className]),
47
            E_WARNING
48
        );
49
    }
50
51
    /**
52
     * @param string $name
53
     * @return static
54
     */
55
    public static function adapterNotSupported(string $name)
56
    {
57
        return new static(
58
            _message(ExceptionMessages::ADAPTER_NOT_SUPPORTED, [$name]),
59
            E_ERROR
60
        );
61
    }
62
63
    /**
64
     * @param string $name
65
     * @return static
66
     */
67
    public static function driverNotSupported(string $name)
68
    {
69
        return new static(
70
            _message(ExceptionMessages::DRIVER_NOT_SUPPORTED, [$name]),
71
            E_ERROR
72
        );
73
    }
74
75
    /**
76
     * @param string $name
77
     * @return static
78
     */
79
    public static function fileNotFound(string $name)
80
    {
81
        return new static(
82
            _message(ExceptionMessages::FILE_NOT_FOUND, [$name]),
83
            E_ERROR
84
        );
85
    }
86
87
    /**
88
     * @param string $subject
89
     * @param string $name
90
     * @return static
91
     */
92
    public static function notFound(string $subject, string $name)
93
    {
94
        return new static(
95
            _message(ExceptionMessages::NOT_FOUND, [$subject, $name]),
96
            E_ERROR
97
        );
98
    }
99
100
    /**
101
     * @param string $instance
102
     * @param string $name
103
     * @return static
104
     */
105
    public static function notInstanceOf(string $instance, string $name)
106
    {
107
        return new static(
108
            _message(ExceptionMessages::NOT_INSTANCE_OF, [$instance, $name]),
109
            E_ERROR
110
        );
111
    }
112
113
    /**
114
     * @param string $name
115
     * @return static
116
     */
117
    public static function cantConnect(string $name)
118
    {
119
        return new static(
120
            _message(ExceptionMessages::CANT_CONNECT, [$name]),
121
            E_ERROR
122
        );
123
    }
124
125
    /**
126
     * @param string $name
127
     * @return static
128
     */
129
130
    public static function missingConfig(string $name)
131
    {
132
        return new static(
133
            _message(ExceptionMessages::MISSING_CONFIG, $name),
134
            E_ERROR
135
        );
136
    }
137
138
    /**
139
     * @param string $name
140
     * @return static
141
     */
142
    public static function requestMethodNotAvailable(string $name)
143
    {
144
        return new static(
145
            _message(ExceptionMessages::UNAVAILABLE_REQUEST_METHOD, [$name]),
146
            E_WARNING
147
        );
148
    }
149
}