Completed
Push — master ( 69f7ce...200493 )
by Alexandr
06:36 queued 03:08
created

Field::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 6
rs 9.4285
ccs 5
cts 5
cp 1
cc 1
eloc 4
nc 1
nop 3
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 Field
12
{
13
    /** @var string */
14
    private $name;
15
16
    /** @var null|string */
17
    private $alias = null;
18
19
    /** @var Argument[] */
20
    protected $arguments;
21
22 36
    public function __construct($name, $alias = null, $arguments = [])
23
    {
24 36
        $this->name  = $name;
25 36
        $this->alias = $alias;
26 36
        $this->arguments = $arguments;
27 36
    }
28
29
    /**
30
     * @return string
31
     */
32 17
    public function getName()
33
    {
34 17
        return $this->name;
35
    }
36
37
    /**
38
     * @param string $name
39
     */
40
    public function setName($name)
41
    {
42
        $this->name = $name;
43
    }
44
45
    /**
46
     * @return null|string
47
     */
48 17
    public function getAlias()
49
    {
50 17
        return $this->alias;
51
    }
52
53
    /**
54
     * @param null|string $alias
55
     */
56
    public function setAlias($alias)
57
    {
58
        $this->alias = $alias;
59
    }
60
61
    public function hasArguments()
62
    {
63
        return (bool)count($this->arguments);
64
    }
65
66
    /**
67
     * @return Argument[]
68
     */
69 1
    public function getArguments()
70
    {
71 1
        return $this->arguments;
72
    }
73
74
    public function addArgument(Argument $argument)
75
    {
76
        $this->arguments[$argument->getName()] = $argument;
77
    }
78
79 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...
80
    {
81 1
        $arguments = [];
82
83 1
        foreach ($this->getArguments() as $argument) {
84
            $arguments[$argument->getName()] = $argument->getValue()->getValue();
85
        }
86
87 1
        return $arguments;
88
    }
89
}