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

QueryType::resolveArguments()   B

Complexity

Conditions 6
Paths 13

Size

Total Lines 27
Code Lines 16

Duplication

Lines 22
Ratio 81.48 %

Code Coverage

Tests 16
CRAP Score 6.0073

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 13
nop 1
dl 22
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\Type;
12
13
use GraphQL\Type\Definition\ObjectType;
14
use GraphQL\Type\Definition\Type;
15
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
17
use Ynlo\GraphQLBundle\Definition\QueryDefinition;
18
use Ynlo\GraphQLBundle\Resolver\ResolverExecutor;
19
use Ynlo\GraphQLBundle\Util\GraphQLBuilder;
20
21
/**
22
 * Class QueryType
23
 */
24
class QueryType extends ObjectType implements
25
    ContainerAwareInterface,
26
    EndpointAwareInterface
27
{
28
    use ContainerAwareTrait;
29
    use EndpointAwareTrait;
30
31
    /**
32
     * QueryType constructor.
33
     *
34
     * @param array $config
35
     */
36 1 View Code Duplication
    public function __construct(array $config = [])
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...
37
    {
38
        $defaults = [
39 1
            'name' => 'Query',
40 1
            'fields' => function () {
41 1
                $queries = [];
42 1
                foreach ($this->endpoint->allQueries() as $query) {
43 1
                    $queries[$query->getName()] = $this->getQueryConfig($query);
44
                }
45
46 1
                return $queries;
47 1
            },
48
        ];
49 1
        parent::__construct(array_merge($defaults, $config));
50 1
    }
51
52
    /**
53
     * @param QueryDefinition $query
54
     *
55
     * @return array
56
     */
57 1
    protected function getQueryConfig(QueryDefinition $query): array
58
    {
59 1
        $config['type'] = Types::get($query->getType());
0 ignored issues
show
Comprehensibility Best Practice introduced by
$config was never initialized. Although not strictly required by PHP, it is generally a good practice to add $config = array(); before regardless.
Loading history...
60 1
        if ($query->isList()) {
61 1
            $config['type'] = Type::listOf($config['type']);
62
        }
63
64 1
        $config['args'] = GraphQLBuilder::buildArguments($query);
65
66 1
        $config['resolve'] = new ResolverExecutor($this->container, $this->endpoint, $query);
67 1
        $config['description'] = $query->getDescription();
68 1
        $config['deprecationReason'] = $query->getDeprecationReason();
69
70 1
        return $config;
71
    }
72
}
73