AstArgumentsTrait   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 93.94%

Importance

Changes 0
Metric Value
wmc 13
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 82
ccs 31
cts 33
cp 0.9394
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A hasArguments() 0 4 1
A hasArgument() 0 4 1
A getArguments() 0 4 1
A getArgumentValue() 0 6 2
A addArgument() 0 4 1
A getArgument() 0 9 2
A setArguments() 0 9 2
A getKeyValueArguments() 0 14 3
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 2/5/17 11:31 AM
7
*/
8
9
namespace Youshido\GraphQL\Parser\Ast;
10
11
12
trait AstArgumentsTrait
13
{
14
15
    /** @var Argument[] */
16
    protected $arguments;
17
18
    private $argumentsCache = null;
19
20
21 3
    public function hasArguments()
22
    {
23 3
        return (bool)count($this->arguments);
24
    }
25
26
    public function hasArgument($name)
27
    {
28
        return array_key_exists($name, $this->arguments);
29
    }
30
31
    /**
32
     * @return Argument[]
33
     */
34 70
    public function getArguments()
35
    {
36 70
        return $this->arguments;
37
    }
38
39
    /**
40
     * @param $name
41
     *
42
     * @return null|Argument
43
     */
44 1
    public function getArgument($name)
45
    {
46 1
        $argument = null;
47 1
        if (isset($this->arguments[$name])) {
48 1
            $argument = $this->arguments[$name];
49 1
        }
50
51 1
        return $argument;
52
    }
53
54 1
    public function getArgumentValue($name)
55
    {
56 1
        $argument = $this->getArgument($name);
57
58 1
        return $argument ? $argument->getValue()->getValue() : null;
59
    }
60
61
    /**
62
     * @param $arguments Argument[]
63
     */
64 99
    public function setArguments(array $arguments)
65
    {
66 99
        $this->arguments = [];
67 99
        $this->argumentsCache = null;
68
69 99
        foreach ($arguments as $argument) {
70 54
            $this->addArgument($argument);
71 99
        }
72 99
    }
73
74 55
    public function addArgument(Argument $argument)
75
    {
76 55
        $this->arguments[$argument->getName()] = $argument;
77 55
    }
78
79 4
    public function getKeyValueArguments()
80
    {
81 4
        if ($this->argumentsCache !== null) {
82 1
            return $this->argumentsCache;
83
        }
84
85 4
        $this->argumentsCache = [];
86
87 4
        foreach ($this->getArguments() as $argument) {
88 4
            $this->argumentsCache[$argument->getName()] = $argument->getValue()->getValue();
89 4
        }
90
91 4
        return $this->argumentsCache;
92
    }
93
}