LogicException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
namespace FigTree\Exceptions;
4
5
use Throwable;
6
use LogicException as PHPLogicException;
7
use FigTree\Exceptions\Concerns\HasSeverity;
8
use FigTree\Exceptions\Contracts\{
9
	SevereExceptionInterface,
10
	LocatableExceptionInterface,
11
};
12
13
/**
14
 * Exception that represents error in the program logic.
15
 * This kind of exception should lead directly to a fix in your code.
16
 */
17
class LogicException extends PHPLogicException implements SevereExceptionInterface, LocatableExceptionInterface
18
{
19
	use HasSeverity;
20
21
	/**
22
	 * Exception that represents error in the program logic.
23
	 * This kind of exception should lead directly to a fix in your code.
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