Passed
Pull Request — master (#169)
by Quang
03:16
created

ListValueNode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 61
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValuesAsArray() 0 5 1
A getValues() 0 3 1
A toArray() 0 6 1
A setValues() 0 4 1
A __toString() 0 5 1
1
<?php
2
3
namespace Digia\GraphQL\Language\Node;
4
5
use Digia\GraphQL\Language\Node\NodeKindEnum;
6
use Digia\GraphQL\Util\SerializationInterface;
7
8
class ListValueNode extends AbstractNode implements ValueNodeInterface
9
{
10
11
    /**
12
     * @var string
13
     */
14
    protected $kind = NodeKindEnum::LIST;
15
16
    /**
17
     * @var array|ValueNodeInterface[]
18
     */
19
    protected $values;
20
21
    /**
22
     * @return array|ValueNodeInterface[]
23
     */
24
    public function getValues(): array
25
    {
26
        return $this->values;
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public function getValuesAsArray(): array
33
    {
34
        return array_map(function (SerializationInterface $node) {
35
            return $node->toArray();
36
        }, $this->values);
37
    }
38
39
    /**
40
     * @param array|ValueNodeInterface[] $values
41
     * @return $this
42
     */
43
    public function setValues(array $values)
44
    {
45
        $this->values = $values;
46
        return $this;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function toArray(): array
53
    {
54
        return [
55
            'kind'   => $this->kind,
56
            'loc'    => $this->getLocationAsArray(),
57
            'values' => $this->getValuesAsArray(),
58
        ];
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    public function __toString(): string
65
    {
66
        return json_encode(array_map(function(ValueNodeInterface $node) {
67
            return $node->getValue();
0 ignored issues
show
Bug introduced by
The method getValue() does not exist on Digia\GraphQL\Language\Node\ValueNodeInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Digia\GraphQL\Language\Node\VariableNode or Digia\GraphQL\Language\Node\ListValueNode or Digia\GraphQL\Language\Node\NullValueNode or Digia\GraphQL\Language\Node\ObjectValueNode. Are you sure you never get one of those? ( Ignorable by Annotation )

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

67
            return $node->/** @scrutinizer ignore-call */ getValue();
Loading history...
68
        }, $this->getValues()));
69
    }
70
}
71