Passed
Push — master ( 4750e8...7ce0c8 )
by Christoffer
02:11
created

ArgumentsTrait::hasArgs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Type\Definition;
4
5
use function Digia\GraphQL\Type\isAssocArray;
6
use function Digia\GraphQL\Util\invariant;
7
8
trait ArgumentsTrait
9
{
10
11
    /**
12
     * @var Argument[]
13
     */
14
    private $_arguments = [];
15
16
    /**
17
     * @return bool
18
     */
19
    public function hasArguments(): bool
20
    {
21
        return !empty($this->_arguments);
22
    }
23
24
    /**
25
     * @return Argument[]
26
     */
27
    public function getArguments(): array
28
    {
29
        return $this->_arguments;
30
    }
31
32
    /**
33
     * @param Argument[] $arguments
34
     * @return $this
35
     * @throws \Exception
36
     */
37
    protected function setArgs(array $arguments)
38
    {
39
        invariant(
40
            isAssocArray($arguments),
41
            'Args must be an associative array with argument names as keys.'
42
        );
43
44
        foreach ($arguments as $argName => $argConfig) {
45
            $this->_arguments[] = new Argument(array_merge($argConfig, ['name' => $argName]));
0 ignored issues
show
Bug introduced by
$argConfig of type Digia\GraphQL\Type\Definition\Argument is incompatible with the type array expected by parameter $array1 of array_merge(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
            $this->_arguments[] = new Argument(array_merge(/** @scrutinizer ignore-type */ $argConfig, ['name' => $argName]));
Loading history...
46
        }
47
48
        return $this;
49
    }
50
}
51