|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FigTree\Exceptions; |
|
4
|
|
|
|
|
5
|
|
|
use Throwable; |
|
6
|
|
|
use UnexpectedValueException as PHPUnexpectedValueException; |
|
7
|
|
|
use FigTree\Exceptions\Concerns\HasSeverity; |
|
8
|
|
|
use FigTree\Exceptions\Contracts\{ |
|
9
|
|
|
SevereExceptionInterface, |
|
10
|
|
|
LocatableExceptionInterface, |
|
11
|
|
|
}; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Exception thrown if a value does not match with a set of values. |
|
15
|
|
|
* Typically this happens when a function calls another function and expects the return value |
|
16
|
|
|
* to be of a certain type or value not including arithmetic or buffer related errors. |
|
17
|
|
|
*/ |
|
18
|
|
|
class UnexpectedValueException extends PHPUnexpectedValueException implements SevereExceptionInterface, LocatableExceptionInterface |
|
19
|
|
|
{ |
|
20
|
|
|
use HasSeverity; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Exception thrown if a value does not match with a set of values. |
|
24
|
|
|
* Typically this happens when a function calls another function and expects the return value |
|
25
|
|
|
* to be of a certain type or value not including arithmetic or buffer related errors. |
|
26
|
|
|
* |
|
27
|
|
|
* @param string $message The Exception message to throw. |
|
28
|
|
|
* @param int $code The Exception code. |
|
29
|
|
|
* @param \Throwable $previous The previous throwable used for the exception chaining. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(string $message = '', int $code = 0, Throwable $previous = null) |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct($message, $code, $previous); |
|
34
|
|
|
|
|
35
|
|
|
$this->severity = E_ERROR; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* If required, set the file and line where the Exception was thrown. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $file |
|
42
|
|
|
* @param int $line |
|
43
|
|
|
* |
|
44
|
|
|
* @return $this |
|
45
|
|
|
*/ |
|
46
|
|
|
public function setLocation(string $file, int $line): LocatableExceptionInterface |
|
47
|
|
|
{ |
|
48
|
|
|
if (file_exists($file)) { |
|
49
|
|
|
$this->file = $file; |
|
50
|
|
|
$this->line = max(0, $line); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|