Completed
Push — master ( 1049ef...ba8cbe )
by Portey
7s
created

Query::getFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 45
    public function __construct($name, $alias = null, $arguments = [], $fields = [])
27
    {
28 45
        $this->name      = $name;
29 45
        $this->alias     = $alias;
30 45
        $this->arguments = $arguments;
31 45
        $this->fields    = $fields;
32 45
    }
33
34 22
    public function getName()
35
    {
36 22
        return $this->name;
37
    }
38
39 1
    public function hasArguments()
40
    {
41 1
        return (bool)count($this->arguments);
42
    }
43
44
    /**
45
     * @return Argument[]
46
     */
47 23
    public function getArguments()
48
    {
49 23
        return $this->arguments;
50
    }
51
52
    /**
53
     * @param $arguments Argument[]
54
     */
55 1
    public function setArguments($arguments)
56
    {
57 1
        $this->arguments = $arguments;
58 1
    }
59
60 2
    public function addArgument(Argument $argument)
61
    {
62 2
        $this->arguments[$argument->getName()] = $argument;
63 2
    }
64
65 1 View Code Duplication
    public function getKeyValueArguments()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67 1
        $arguments = [];
68
69 1
        foreach ($this->getArguments() as $argument) {
70 1
            $arguments[$argument->getName()] = $argument->getValue()->getValue();
71
        }
72
73 1
        return $arguments;
74
    }
75
76
    /**
77
     * @return Field[]|Query[]|FragmentInterface[]
78
     */
79 20
    public function getFields()
80
    {
81 20
        return $this->fields;
82
    }
83
84
    /**
85
     * @return bool
86
     */
87 18
    public function hasFields()
88
    {
89 18
        return (bool)count($this->fields);
90
    }
91
92
    /**
93
     * @param Field[]|Query[] $fields
94
     */
95 1
    public function setFields($fields)
96
    {
97 1
        $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...
98 1
    }
99
100 22
    public function getAlias()
101
    {
102 22
        return $this->alias;
103
    }
104
105
    public function hasField($name, $deep = false)
106
    {
107
        foreach ($this->getFields() as $field) {
108
            if ($field->getName() == $name) {
109
                return true;
110
            }
111
112
            if ($deep && $field instanceof Query) {
113
                if ($field->hasField($name)) {
114
                    return true;
115
                }
116
            }
117
        }
118
119
        return false;
120
    }
121
122
}
123