Passed
Push — master ( c39fb6...9e9a0d )
by Rafael
04:42
created

GraphQLBuilder::buildArguments()   B

Complexity

Conditions 6
Paths 13

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6.0073

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 13
nop 1
dl 0
loc 27
ccs 16
cts 17
cp 0.9412
crap 6.0073
rs 8.439
c 0
b 0
f 0
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Util;
12
13
use GraphQL\Type\Definition\Type;
14
use Ynlo\GraphQLBundle\Definition\ArgumentAwareInterface;
15
use Ynlo\GraphQLBundle\Type\Types;
16
17
/**
18
 * GraphQLBuilder
19
 */
20
class GraphQLBuilder
21
{
22
    /**
23
     * @param ArgumentAwareInterface $argumentAware
24
     *
25
     * @return array
26
     */
27 1
    public static function buildArguments(ArgumentAwareInterface $argumentAware)
28
    {
29 1
        $args = [];
30 1
        foreach ($argumentAware->getArguments() as $argDefinition) {
31 1
            $arg = [];
32 1
            $arg['description'] = $argDefinition->getDescription();
33 1
            $argType = Types::get($argDefinition->getType());
34
35 1
            if ($argDefinition->isList()) {
36 1
                if ($argDefinition->isNonNullList()) {
37 1
                    $argType = Type::nonNull($argType);
38
                }
39 1
                $argType = Type::listOf($argType);
40
            }
41
42 1
            if ($argDefinition->isNonNull()) {
43 1
                $argType = Type::nonNull($argType);
44
            }
45
46 1
            $arg['type'] = $argType;
47 1
            if ($argDefinition->getDefaultValue()) {
48
                $arg['defaultValue'] = $argDefinition->getDefaultValue();
49
            }
50 1
            $args[$argDefinition->getName()] = $arg;
51
        }
52
53 1
        return $args;
54
    }
55
}
56