OutOfBoundsException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setLocation() 0 8 2
1
<?php
2
3
namespace FigTree\Exceptions;
4
5
use Throwable;
6
use OutOfBoundsException as PHPOutOfBoundsException;
7
use FigTree\Exceptions\Concerns\HasSeverity;
8
use FigTree\Exceptions\Contracts\{
9
	SevereExceptionInterface,
10
	LocatableExceptionInterface,
11
};
12
13
/**
14
 * Exception thrown if a value is not a valid key.
15
 * This represents errors that cannot be detected at compile time.
16
 */
17
class OutOfBoundsException extends PHPOutOfBoundsException implements SevereExceptionInterface, LocatableExceptionInterface
18
{
19
	use HasSeverity;
20
21
	/**
22
	 * Exception thrown if a value is not a valid key.
23
	 * This represents errors that cannot be detected at compile time.
24
	 *
25
	 * @param string $message The Exception message to throw.
26
	 * @param int $code The Exception code.
27
	 * @param \Throwable $previous The previous throwable used for the exception chaining.
28
	 */
29
	public function __construct(string $message = '', int $code = 0, Throwable $previous = null)
30
	{
31
		parent::__construct($message, $code, $previous);
32
33
		$this->severity = E_ERROR;
34
	}
35
36
	/**
37
	 * If required, set the file and line where the Exception was thrown.
38
	 *
39
	 * @param string $file
40
	 * @param int $line
41
	 *
42
	 * @return $this
43
	 */
44
	public function setLocation(string $file, int $line): LocatableExceptionInterface
45
	{
46
		if (file_exists($file)) {
47
			$this->file = $file;
48
			$this->line = max(0, $line);
49
		}
50
51
		return $this;
52
	}
53
}
54