Completed
Push — master ( 120e4f...bd44b4 )
by Portey
07:04
created

ArgumentsAwareTrait::removeArgument()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4286
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
/*
3
* This file is a part of graphql-youshido project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 12/1/15 11:07 PM
7
*/
8
9
namespace Youshido\GraphQL\Type\Config\Traits;
10
11
12
use Youshido\GraphQL\Type\Field\InputField;
13
use Youshido\GraphQL\Type\TypeMap;
14
use Youshido\GraphQL\Validator\Exception\ConfigurationException;
15
16
trait ArgumentsAwareTrait
17
{
18
    protected $arguments = [];
19
20 20
    public function buildArguments()
21
    {
22 20
        $sourceArguments = empty($this->data['args']) ? [] : $this->data['args'];
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23 20
        foreach ($sourceArguments as $argumentName => $argumentInfo) {
24 11
            $this->addArgument($argumentName, $argumentInfo['type'], $argumentInfo);
25 20
        }
26 20
    }
27
28 12
    public function addArgument($name, $type, $config = [])
29
    {
30 12
        if (!TypeMap::isInputType($type)) {
31
            throw new ConfigurationException('Argument input type ' . $type . ' is not supported');
32
        }
33
34 12
        $config['name'] = $name;
35 12
        $config['type'] = is_string($type) ? TypeMap::getScalarTypeObject($type) : $type;
36
37 12
        $this->arguments[$name] = new InputField($config);
38
39 12
        return $this;
40
    }
41
42
    /**
43
     * @param $name
44
     *
45
     * @return InputField
46
     */
47 5
    public function getArgument($name)
48
    {
49 5
        return $this->hasArgument($name) ? $this->arguments[$name] : null;
50
    }
51
52
    /**
53
     * @param $name
54
     *
55
     * @return bool
56
     */
57 5
    public function hasArgument($name)
58
    {
59 5
        return array_key_exists($name, $this->arguments);
60
    }
61
62
    /**
63
     * @return InputField[]
64
     */
65 13
    public function getArguments()
66
    {
67 13
        return $this->arguments;
68
    }
69
70
    public function removeArgument($name)
71
    {
72
        if ($this->hasArgument($name)) {
73
            unset($this->arguments[$name]);
74
        }
75
    }
76
77
}