Completed
Push — master ( cbfed7...c39fb6 )
by Rafael
05:06
created

QueryGetAllNodesAnnotationParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 23 3
A __construct() 0 3 1
A supports() 0 3 1
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\Definition\Loader\Annotation;
12
13
use Doctrine\Common\Util\Inflector;
14
use Ynlo\GraphQLBundle\Annotation;
15
use Ynlo\GraphQLBundle\Definition\ConnectionDefinitionBuilder;
16
use Ynlo\GraphQLBundle\Definition\QueryDefinition;
17
use Ynlo\GraphQLBundle\Definition\Registry\DefinitionManager;
18
19
/**
20
 * Resolve queries
21
 */
22
class QueryGetAllNodesAnnotationParser implements AnnotationParserInterface
23
{
24
    use AnnotationReaderAwareTrait;
25
    use AnnotationParserHelper;
26
27
    /**
28
     * @var ConnectionDefinitionBuilder
29
     */
30
    protected $connectionBuilder;
31
32
    /**
33
     * QueryGetAllNodesAnnotationParser constructor.
34
     *
35
     * @param ConnectionDefinitionBuilder $connectionBuilder
36
     */
37 1
    public function __construct(ConnectionDefinitionBuilder $connectionBuilder)
38
    {
39 1
        $this->connectionBuilder = $connectionBuilder;
40 1
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    public function supports($annotation): bool
46
    {
47 1
        return $annotation instanceof Annotation\QueryGetAll;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 1
    public function parse($annotation, \ReflectionClass $refClass, DefinitionManager $definitionManager)
54
    {
55
        /** @var Annotation\QueryGetAll $annotation */
56 1
        if ($annotation->name) {
57
            $name = $annotation->name;
58
        } else {
59 1
            $name = 'all'.Inflector::pluralize(ucfirst($this->getDefaultName($refClass, $definitionManager)));
60
        }
61
62 1
        $query = new QueryDefinition();
63 1
        $query->setName($name);
64
65 1
        $objectDefinition = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $objectDefinition is dead and can be removed.
Loading history...
66 1
        $typeName = null;
67 1
        if ($objectType = $this->reader->getClassAnnotation($refClass, Annotation\ObjectType::class)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $objectType is dead and can be removed.
Loading history...
68 1
            $typeName = $definitionManager->getTypeForClass($refClass->getName());
69
        }
70
71 1
        $this->connectionBuilder->setEndpoint($definitionManager->getEndpoint());
72 1
        $this->connectionBuilder->setLimit($annotation->limit);
73 1
        $this->connectionBuilder->setDeprecationReason($annotation->deprecationReason);
74 1
        $this->connectionBuilder->setDescription($annotation->description);
75 1
        $this->connectionBuilder->build($query, $typeName);
76 1
    }
77
}
78