Passed
Branch dev (e23247)
by Alan
01:51
created

UnexpectedTypeException::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 Throwable;
6
7
/**
8
 * Exception thrown when a value is not of an expected type.
9
 */
10
class UnexpectedTypeException extends LogicException
11
{
12
	/**
13
	 * Exception thrown when a value is not of an expected type.
14
	 *
15
	 * @param mixed $value Actual value.
16
	 * @param string $expected The name of the expected type.
17
	 * @param int $code The Exception code.
18
	 * @param \Throwable $previous The previous throwable used for the exception chaining.
19
	 */
20
	public function __construct($value, string $expected, int $code = 0, Throwable $previous = null)
21
	{
22
		$message = sprintf(
23
			'Expected value of type %s; %s given.',
24
			$expected,
25
			(is_object($value) ? get_class($value) : gettype($value))
26
		);
27
28
		parent::__construct($message, $code, $previous);
29
	}
30
}
31