Failed Conditions
Push — mixed-collections ( 23b545...27e0f6 )
by Michael
02:15
created

NamedEntry::__construct()   A

Complexity

Conditions 5
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 12
rs 9.6111
c 0
b 0
f 0
cc 5
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Parser\Ast\Collection;
6
7
use Doctrine\Annotations\Parser\Ast\ClassConstantFetch;
8
use Doctrine\Annotations\Parser\Ast\ConstantFetch;
9
use Doctrine\Annotations\Parser\Ast\Scalar\Identifier;
10
use Doctrine\Annotations\Parser\Ast\Scalar\IntegerScalar;
11
use Doctrine\Annotations\Parser\Ast\Scalar\StringScalar;
12
use Doctrine\Annotations\Parser\Ast\ValuableNode;
13
use Doctrine\Annotations\Parser\Ast\Value;
14
use Doctrine\Annotations\Parser\Visitor\Visitor;
15
use function assert;
16
17
final class NamedEntry implements Entry
18
{
19
    /** @var StringScalar|IntegerScalar|ConstantFetch|ClassConstantFetch */
20
    private $key;
21
22
    /** @var ValuableNode */
23
    private $value;
24
25
    public function __construct(Value $key, ValuableNode $value)
26
    {
27
        assert(
28
            $key instanceof StringScalar
29
            || $key instanceof IntegerScalar
30
            || $key instanceof Identifier
31
            || $key instanceof ConstantFetch
32
            || $key instanceof ClassConstantFetch
33
        );
34
35
        $this->key   = $key;
36
        $this->value = $value;
37
    }
38
39
    /**
40
     * @return ClassConstantFetch|ConstantFetch|IntegerScalar|StringScalar|null
41
     */
42
    public function getKey() : ?Value
43
    {
44
        return $this->key;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->key could return the type Doctrine\Annotations\Par...arser\Ast\ConstantFetch which is incompatible with the type-hinted return Doctrine\Annotations\Parser\Ast\Value|null. Consider adding an additional type-check to rule them out.
Loading history...
45
    }
46
47
    public function getValue() : ValuableNode
48
    {
49
        return $this->value;
50
    }
51
52
    public function dispatch(Visitor $visitor) : void
53
    {
54
        $visitor->visitCollectionNamedEntry($this);
55
    }
56
}
57