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

Exception::onFileLine()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace FigTree\Exceptions;
4
5
use Exception as PHPException;
6
use FigTree\Exceptions\Concerns\HasSeverity;
7
use FigTree\Exceptions\Contracts\{
8
	SevereExceptionInterface,
9
	LocatableExceptionInterface,
10
};
11
12
class Exception extends PHPException implements SevereExceptionInterface, LocatableExceptionInterface
13
{
14
	use HasSeverity;
15
16
	/**
17
	 * If required, set the file and line where the Exception was thrown.
18
	 *
19
	 * @param string $file
20
	 * @param int $line
21
	 *
22
	 * @return $this
23
	 */
24
	public function setLocation(string $file, int $line): LocatableExceptionInterface
25
	{
26
		if (file_exists($file)) {
27
			$this->file = $file;
28
			$this->line = max(0, $line);
29
		}
30
31
		return $this;
32
	}
33
}
34