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

MutationUpdateAnnotationParser::supports()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 3
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 3
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Definition\Loader\Annotation;
12
13
use Ynlo\GraphQLBundle\Annotation;
14
use Ynlo\GraphQLBundle\Definition\MutationDefinition;
15
use Ynlo\GraphQLBundle\Definition\Registry\DefinitionManager;
16
use Ynlo\GraphQLBundle\Model\UpdateNodePayload;
17
use Ynlo\GraphQLBundle\Mutation\UpdateNodeMutation;
18
19
/**
20
 * Resolve queries
21
 */
22 View Code Duplication
class MutationUpdateAnnotationParser extends MutationAnnotationParser
0 ignored issues
show
Duplication introduced by
This class 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...
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 1
    public function supports($annotation): bool
28
    {
29 1
        return $annotation instanceof Annotation\MutationUpdate;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 1
    public function parse($annotation, \ReflectionClass $refClass, DefinitionManager $definitionManager)
36
    {
37 1
        if (!$annotation->name) {
38 1
            $annotation->name = 'update'.ucfirst($this->getDefaultName($refClass, $definitionManager));
39
        }
40
41 1
        parent::parse($annotation, $refClass, $definitionManager);
42 1
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 1
    public function createMutation(Annotation\Mutation $annotation): MutationDefinition
48
    {
49 1
        $mutation = parent::createMutation($annotation);
50 1
        if (!$annotation->resolver) {
51 1
            $mutation->setResolver(UpdateNodeMutation::class);
52
        }
53
54 1
        if (!$annotation->payload) {
55 1
            $mutation->setType(UpdateNodePayload::class);
56
        }
57
58 1
        return $mutation;
59
    }
60
}
61