InvalidTypeException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
1
<?php
2
declare(strict_types=1);
3
4
namespace MarcinOrlowski\ResponseBuilder\Exceptions;
5
6
use MarcinOrlowski\ResponseBuilder\Contracts\InvalidTypeExceptionContract;
7
8
/**
9
 * Laravel API Response Builder
10
 *
11
 * @package   MarcinOrlowski\ResponseBuilder
12
 *
13
 * @author    Marcin Orlowski <mail (#) marcinOrlowski (.) com>
14
 * @copyright 2016-2021 Marcin Orlowski
15
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
16
 * @link      https://github.com/MarcinOrlowski/laravel-api-response-builder
17
 */
18
class InvalidTypeException extends \Exception implements InvalidTypeExceptionContract
19
{
20
	/**
21
	 * NotAnTypeBaseException constructor.
22
	 *
23
	 * @param string       $var_name      Name of the variable (to be included in error message)
24
	 * @param string|array $allowed_types Array of allowed types [Type::*]
25
	 * @param string       $type          Current type of the $value
26
	 */
27
	public function __construct(string $var_name, string $type, array $allowed_types)
28
	{
29
		switch (\count($allowed_types)) {
30
			case 0:
31
				throw new \InvalidArgumentException('allowed_types array must not be empty.');
32
			case 1:
33
				$msg = '"%s" must be %s but %s found.';
34
				break;
35
			default;
36
				$msg = '"%s" must be one of allowed types: %s but %s found.';
37
				break;
38
		}
39
40
		parent::__construct(\sprintf($msg, $var_name, implode(', ', $allowed_types), $type));
41
	}
42
43
}
44