Passed
Pull Request — master (#23)
by Christoffer
02:09
created

ValueLiteralTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A getValueAsArray() 0 3 2
A setValue() 0 4 1
1
<?php
2
3
namespace Digia\GraphQL\Language\AST\Node;
4
5
use Digia\GraphQL\Util\SerializationInterface;
6
7
trait ValueLiteralTrait
8
{
9
10
    /**
11
     * @var ValueNodeInterface|SerializationInterface|null
12
     */
13
    protected $value;
14
15
    /**
16
     * @return ValueNodeInterface|null
17
     */
18
    public function getValue(): ?ValueNodeInterface
19
    {
20
        return $this->value;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->value could return the type Digia\GraphQL\Util\SerializationInterface which is incompatible with the type-hinted return null|Digia\GraphQL\Langu...Node\ValueNodeInterface. Consider adding an additional type-check to rule them out.
Loading history...
21
    }
22
23
    /**
24
     * @return array
25
     */
26
    public function getValueAsArray(): array
27
    {
28
        return null !== $this->value ? $this->value->toArray() : null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return null !== $this->v...value->toArray() : null could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
Bug introduced by
The method toArray() does not exist on Digia\GraphQL\Language\AST\Node\ValueNodeInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Digia\GraphQL\Language\AST\Node\ValueNodeInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        return null !== $this->value ? $this->value->/** @scrutinizer ignore-call */ toArray() : null;
Loading history...
29
    }
30
31
    /**
32
     * @param ValueNodeInterface|null $value
33
     * @return $this
34
     */
35
    public function setValue(?ValueNodeInterface $value)
36
    {
37
        $this->value = $value;
38
        return $this;
39
    }
40
}
41