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

BadMethodCallException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
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 BadMethodCallException as PHPBadMethodCallException;
7
use FigTree\Exceptions\Concerns\HasSeverity;
8
use FigTree\Exceptions\Contracts\{
9
	SevereExceptionInterface,
10
	LocatableExceptionInterface,
11
};
12
13
/**
14
 * Exception thrown if a callback refers to an undefined method or if some arguments are missing
15
 */
16
class BadMethodCallException extends PHPBadMethodCallException implements SevereExceptionInterface, LocatableExceptionInterface
17
{
18
	use HasSeverity;
19
20
	/**
21
	 * Exception thrown if a callback refers to an undefined method or if some arguments are missing.
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 onFileLine(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