Total Complexity | 8 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
9 | class LiteralArgument implements LiteralArgumentInterface |
||
10 | { |
||
11 | public const TYPE_ARRAY = 'array'; |
||
12 | public const TYPE_BOOL = 'boolean'; |
||
13 | public const TYPE_BOOLEAN = 'boolean'; |
||
14 | public const TYPE_CALLABLE = 'callable'; |
||
15 | public const TYPE_DOUBLE = 'double'; |
||
16 | public const TYPE_FLOAT = 'double'; |
||
17 | public const TYPE_INT = 'integer'; |
||
18 | public const TYPE_INTEGER = 'integer'; |
||
19 | public const TYPE_OBJECT = 'object'; |
||
20 | public const TYPE_STRING = 'string'; |
||
21 | |||
22 | /** |
||
23 | * @var mixed |
||
24 | */ |
||
25 | protected $value; |
||
26 | |||
27 | 27 | public function __construct($value, ?string $type = null) |
|
28 | { |
||
29 | if ( |
||
30 | 27 | null === $type |
|
31 | 27 | || ($type === self::TYPE_CALLABLE && is_callable($value)) |
|
32 | 27 | || ($type === self::TYPE_OBJECT && is_object($value)) |
|
33 | 27 | || gettype($value) === $type |
|
34 | ) { |
||
35 | 24 | $this->value = $value; |
|
36 | } else { |
||
37 | 3 | throw new InvalidArgumentException('Incorrect type for value.'); |
|
38 | } |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | 18 | public function getValue() |
|
47 | } |
||
48 | } |
||
49 |