Completed
Push — master ( f9f0ef...24a695 )
by Portey
05:15
created

Query::getKeyValueArguments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.4286
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * Date: 23.11.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Parser\Ast;
9
10
11
class Query
12
{
13
14
    /** @var string */
15
    protected $name;
16
17
    /** @var string */
18
    protected $alias;
19
20
    /** @var Argument[] */
21
    protected $arguments;
22
23
    /** @var Field[]|Query[] */
24
    protected $fields;
25
26 33
    public function __construct($name, $alias = null, $arguments = [], $fields = [])
27
    {
28 33
        $this->name      = $name;
29 33
        $this->alias     = $alias;
30 33
        $this->arguments = $arguments;
31 33
        $this->fields    = $fields;
32 33
    }
33
34 18
    public function getName()
35
    {
36 18
        return $this->name;
37
    }
38
39
    public function hasArguments()
40
    {
41
        return (bool)count($this->arguments);
42
    }
43
44
    /**
45
     * @return Argument[]
46
     */
47 18
    public function getArguments()
48
    {
49 18
        return $this->arguments;
50
    }
51
52
    public function addArgument(Argument $argument)
53
    {
54
        $this->arguments[$argument->getName()] = $argument;
55
    }
56
57
    public function getKeyValueArguments()
58
    {
59
        $arguments = [];
60
61
        foreach ($this->getArguments() as $argument) {
62
            $arguments[$argument->getName()] = $argument->getValue()->getValue();
63
        }
64
65
        return $arguments;
66
    }
67
68
    /**
69
     * @return Field[]|Query[]
70
     */
71 16
    public function getFields()
72
    {
73 16
        return $this->fields;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function hasFields()
80
    {
81
        return (bool)count($this->fields);
82
    }
83
84
    /**
85
     * @param Field[]|Query[] $fields
86
     */
87
    public function setFields($fields)
88
    {
89
        $this->fields = $fields;
0 ignored issues
show
Documentation Bug introduced by
It seems like $fields of type array<integer,object<You...phQL\Parser\Ast\Query>> is incompatible with the declared type array<integer,object<You...phQL\Parser\Ast\Query>> of property $fields.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
90
    }
91
92 3
    public function getAlias()
93
    {
94 3
        return $this->alias;
95
    }
96
97 17
    public function hasAlias()
98
    {
99 17
        return $this->alias ? true : false;
100
    }
101
102
}