1 | <?php |
||
8 | class gwCoreException extends \Exception |
||
9 | { |
||
10 | /** |
||
11 | * A logic error. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | const ERR_LOGIC_ERROR = 'gwCoreException::logic_error'; |
||
16 | |||
17 | /** |
||
18 | * Method does not exist on object |
||
19 | * info = name of method called. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | const ERR_BAD_METHOD_CALL = 'gwCoreException::bad_method_call'; |
||
24 | |||
25 | /** |
||
26 | * Argument passed to a method is invalid, and is not one of the following: |
||
27 | * - invalid type |
||
28 | * - out of bounds |
||
29 | * - out of range. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | const ERR_INVALID_ARGUMENT = 'gwCoreException::invalid_argument'; |
||
34 | |||
35 | /** |
||
36 | * Required argument is missing. Possibly within an array passed as an |
||
37 | * argument. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | const ERR_MISSING_ARGUMENT = 'gwCoreException::missing_argument'; |
||
42 | |||
43 | /** |
||
44 | * Argument passed to a method has the wrong type. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | const ERR_INVALID_TYPE = 'gwCoreException::invalid_type'; |
||
49 | |||
50 | /** |
||
51 | * Argument passed is out of the allowed numeric range. |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | const ERR_OUT_OF_RANGE = 'gwCoreException::out_of_range'; |
||
56 | |||
57 | /** |
||
58 | * Argument passed is out of the allowed set of possible options |
||
59 | * Could be used |
||
60 | * - when an array key does not exist |
||
61 | * - when an property does not exist on an object |
||
62 | * - when a value is not within a specific range. |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | const ERR_OUT_OF_BOUNDS = 'gwCoreException::out_of_bounds'; |
||
67 | |||
68 | /** |
||
69 | * Thrown when trying to create an entry with a key that should be unique. |
||
70 | * E.g. insert into database, create element in array. |
||
71 | * |
||
72 | * @var string |
||
73 | */ |
||
74 | const ERR_KEY_EXISTS = 'gwCoreException::key_exists'; |
||
75 | |||
76 | /** |
||
77 | * Thrown when trying to retrieve an entry with a key and no entry exists. |
||
78 | * E.g. read from database, read from array. |
||
79 | * |
||
80 | * @var string |
||
81 | */ |
||
82 | const ERR_KEY_NOT_EXIST = 'gwCoreException::key_not_exist'; |
||
83 | |||
84 | /** |
||
85 | * Thrown by a method when caller does not have sufficient privileges. |
||
86 | * E.g. database entry exists, but is blocked, inactive, unconfirmed, etc. |
||
87 | * |
||
88 | * @var string |
||
89 | */ |
||
90 | const ERR_ACCESS_DENIED = 'gwCoreException::access_denied'; |
||
91 | |||
92 | /** |
||
93 | * Value returned by method or function was unexpected. |
||
94 | * |
||
95 | * @var string |
||
96 | */ |
||
97 | const ERR_UNEXPECTED_VALUE = 'gwCoreException::unexpected_value'; |
||
98 | |||
99 | /** |
||
100 | * Container is full and someone is trying to add something to it. |
||
101 | * |
||
102 | * @var string |
||
103 | */ |
||
104 | const ERR_OVERFLOW = 'gwCoreException::overflow'; |
||
105 | |||
106 | /** |
||
107 | * Container is empty and someone is trying to remove something from it. |
||
108 | * |
||
109 | * @var string |
||
110 | */ |
||
111 | const ERR_UNDERFLOW = 'gwCoreException::underflow'; |
||
112 | |||
113 | /** |
||
114 | * @var gwCoreExceptionInfo |
||
115 | */ |
||
116 | protected $info; |
||
117 | |||
118 | /** |
||
119 | * Constructor. |
||
120 | * |
||
121 | * @param string $message |
||
122 | * @param gwCoreExceptionInfo|string|null $info |
||
123 | * @param int $code |
||
124 | * @param \Exception|null $previous |
||
125 | */ |
||
126 | public function __construct($message, $info = null, $code = 0, \Exception $previous = null) |
||
135 | |||
136 | /** |
||
137 | * @return string representation of this Exception |
||
138 | */ |
||
139 | public function __toString() |
||
143 | |||
144 | /** |
||
145 | * @param string $key |
||
146 | * @param string $value |
||
147 | */ |
||
148 | public function __set($key, $value) |
||
156 | |||
157 | /** |
||
158 | * @param string $key |
||
159 | * |
||
160 | * @return mixed |
||
161 | */ |
||
162 | public function __get($key) |
||
171 | |||
172 | /** |
||
173 | * @return gwCoreExceptionInfo |
||
174 | */ |
||
175 | public function getInfo() |
||
179 | } |
||
180 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.