Completed
Push — master ( 0f7b0a...750008 )
by Christoffer
02:09
created

NameTrait::getNameAsArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Language\AST\Node;
4
5
trait NameTrait
6
{
7
8
    /**
9
     * @var NameNode|null
10
     */
11
    protected $name;
12
13
    /**
14
     * @return NameNode|null
15
     */
16
    public function getName(): ?NameNode
17
    {
18
        return $this->name;
19
    }
20
21
    /**
22
     * @return string|null
23
     */
24
    public function getNameValue(): ?string
25
    {
26
        return null !== $this->name ? $this->name->getValue() : null;
27
    }
28
29
    /**
30
     * @return array|null
31
     */
32
    public function getNameAsArray(): ?array
33
    {
34
        return null !== $this->name ? $this->name->toArray() : null;
35
    }
36
37
    /**
38
     * @param NameNode|null $name
39
     * @return $this
40
     */
41
    public function setName(?NameNode $name)
42
    {
43
        $this->name = $name;
44
        return $this;
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function __toString(): string
51
    {
52
        return $this->getNameValue() ?? '';
53
    }
54
}
55