Passed
Push — master ( f0144a...338223 )
by Alan
02:17
created

UnexpectedValueException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 36
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A onFileLine() 0 8 2
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 onFileLine(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