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

DomainException::onFileLine()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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