InvalidRenderTarget   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A format_message() 0 6 1
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