Passed
Push — master ( 42ae0f...32b24a )
by Marcin
08:00 queued 11s
created

InvalidTypeException   A

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