InvalidRenderTarget::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 1
nop 4
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ICanBoogie\Render;
13
14
use ICanBoogie\Accessor\AccessorTrait;
15
16
/**
17
 * Exception thrown when the target to render is invalid.
18
 *
19
 * @property-read mixed $target
20
 */
21
class InvalidRenderTarget extends \InvalidArgumentException implements Exception
22
{
23
	use AccessorTrait;
24
25
	/**
26
	 * @var mixed
27
	 */
28
	private $target;
29
30
	/**
31
	 * InvalidRenderTarget constructor.
32
	 *
33
	 * @param mixed $target
34
	 * @param string $message
35
	 * @param int $code
36
	 * @param \Exception|null $previous
37
	 */
38
	public function __construct($target, $message = null, $code = 500, \Exception $previous = null)
39
	{
40
		$this->target = $target;
41
42
		parent::__construct($message ?: $this->format_message($target), $code, $previous);
43
	}
44
45
	/**
46
	 * Format exception message.
47
	 *
48
	 * @param mixed $target
49
	 *
50
	 * @return string
51
	 */
52
	protected function format_message($target)
53
	{
54
		$type = gettype($target);
55
56
		return "Invalid render target. Expected object or array, got: $type (`$target`)";
57
	}
58
}
59