Completed
Push — master ( 552805...97be4b )
by Portey
03:57
created

Query::getAlias()   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 2
Bugs 0 Features 0
Metric Value
c 2
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 10
    public function __construct($name, $alias = null, $arguments = [], $fields = [])
27
    {
28 10
        $this->name      = $name;
29 10
        $this->alias     = $alias;
30 10
        $this->arguments = $arguments;
31 10
        $this->fields    = $fields;
32 10
    }
33
34 4
    public function getName()
35
    {
36 4
        return $this->name;
37
    }
38
39
    public function hasArguments()
40
    {
41
        return (bool)count($this->arguments);
42
    }
43
44
    /**
45
     * @return Argument[]
46
     */
47 4
    public function getArguments()
48
    {
49 4
        return $this->arguments;
50
    }
51
52
    public function getKeyValueArguments()
53
    {
54
        $arguments = [];
55
56
        foreach ($this->getArguments() as $argument) {
57
            $arguments[$argument->getName()] = $argument->getValue()->getValue();
58
        }
59
60
        return $arguments;
61
    }
62
63
    /**
64
     * @return Field[]|Query[]
65
     */
66 3
    public function getFields()
67
    {
68 3
        return $this->fields;
69
    }
70
71
    /**
72
     * @return bool
73
     */
74
    public function hasFields()
75
    {
76
        return (bool)count($this->fields);
77
    }
78
79
    /**
80
     * @param Field[]|Query[] $fields
81
     */
82
    public function setFields($fields)
83
    {
84
        $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...
85
    }
86
87 1
    public function getAlias()
88
    {
89 1
        return $this->alias;
90
    }
91
92 4
    public function hasAlias()
93
    {
94 4
        return $this->alias ? true : false;
95
    }
96
97
}