Completed
Pull Request — master (#103)
by Christoffer
02:14
created

DefaultValueTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultValueAsArray() 0 3 2
A hasDefaultValue() 0 3 1
A getDefaultValue() 0 3 1
1
<?php
2
3
namespace Digia\GraphQL\Language\Node;
4
5
use Digia\GraphQL\Util\SerializationInterface;
6
7
trait DefaultValueTrait
8
{
9
10
    /**
11
     * @var ValueNodeInterface|SerializationInterface|null
12
     */
13
    protected $defaultValue;
14
15
    /**
16
     * @return bool
17
     */
18
    public function hasDefaultValue(): bool
19
    {
20
        return null !== $this->defaultValue;
21
    }
22
23
    /**
24
     * @return ValueNodeInterface|SerializationInterface|null
25
     */
26
    public function getDefaultValue(): ?ValueNodeInterface
27
    {
28
        return $this->defaultValue;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->defaultValue 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...
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public function getDefaultValueAsArray(): ?array
35
    {
36
        return null !== $this->defaultValue ? $this->defaultValue->toArray() : null;
0 ignored issues
show
Bug introduced by
The method toArray() does not exist on Digia\GraphQL\Language\Node\ValueNodeInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Digia\GraphQL\Language\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

36
        return null !== $this->defaultValue ? $this->defaultValue->/** @scrutinizer ignore-call */ toArray() : null;
Loading history...
37
    }
38
}
39