LiteralArgument   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 21
dl 0
loc 38
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
B __construct() 0 11 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Container\Argument;
6
7
use InvalidArgumentException;
8
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()
45
    {
46 18
        return $this->value;
47
    }
48
}
49