UnexpectedTypeException::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 9
rs 10
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