Passed
Push — master ( 59c59c...91bfb1 )
by Alan
02:13
created

InvalidArgumentException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 34
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 InvalidArgumentException as PHPInvalidArgumentException;
7
use FigTree\Exceptions\Concerns\HasSeverity;
8
use FigTree\Exceptions\Contracts\{
9
	SevereExceptionInterface,
10
	LocatableExceptionInterface,
11
};
12
13
/**
14
 * Exception thrown if an argument is not of the expected type.
15
 */
16
class InvalidArgumentException extends PHPInvalidArgumentException implements SevereExceptionInterface, LocatableExceptionInterface
17
{
18
	use HasSeverity;
19
20
	/**
21
	 * Exception thrown if an argument is not of the expected type.
22
	 *
23
	 * @param string $message The Exception message to throw.
24
	 * @param int $code The Exception code.
25
	 * @param \Throwable $previous The previous throwable used for the exception chaining.
26
	 */
27
	public function __construct(string $message = '', int $code = 0, Throwable $previous = null)
28
	{
29
		parent::__construct($message, $code, $previous);
30
31
		$this->severity = E_ERROR;
32
	}
33
34
	/**
35
	 * If required, set the file and line where the Exception was thrown.
36
	 *
37
	 * @param string $file
38
	 * @param int $line
39
	 *
40
	 * @return $this
41
	 */
42
	public function setLocation(string $file, int $line): LocatableExceptionInterface
43
	{
44
		if (file_exists($file)) {
45
			$this->file = $file;
46
			$this->line = max(0, $line);
47
		}
48
49
		return $this;
50
	}
51
}
52