Completed
Push — master ( 9e9a0d...740d0f )
by Rafael
04:13
created

UpdateNode   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 38.6 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 22
loc 57
ccs 16
cts 20
cp 0.8
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A returnPayload() 7 7 2
A preUpdate() 0 2 1
A postUpdate() 0 2 1
A process() 12 12 3
A onSubmit() 0 7 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Mutation;
12
13
use Ynlo\GraphQLBundle\Error\NodeNotFoundException;
14
use Ynlo\GraphQLBundle\Extension\ExtensionManager;
15
use Ynlo\GraphQLBundle\Model\NodeInterface;
16
use Ynlo\GraphQLBundle\Model\UpdateNodePayload;
17
use Ynlo\GraphQLBundle\Validator\ConstraintViolationList;
18
19
/**
20
 * Class UpdateNodeMutation
21
 */
22
class UpdateNode extends AbstractMutationResolver
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 1 View Code Duplication
    protected function process(&$data)
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...
28
    {
29 1
        $this->preUpdate($data);
30 1
        foreach ($this->container->get(ExtensionManager::class)->getExtensions() as $extension) {
31
            $extension->preUpdate($data, $this, $this->context);
32
        }
33
34 1
        $this->getManager()->flush();
35
36 1
        $this->postUpdate($data);
37 1
        foreach ($this->container->get(ExtensionManager::class)->getExtensions() as $extension) {
38
            $extension->postUpdate($data, $this, $this->context);
39
        }
40 1
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    protected function onSubmit($inputSource, &$normData)
46
    {
47 1
        if ($normData instanceof NodeInterface && $normData->getId()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $normData->getId() of type null|integer is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
48 1
            return;
49
        }
50
51
        throw new NodeNotFoundException();
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 1 View Code Duplication
    protected function returnPayload($data, ConstraintViolationList $violations, $inputSource)
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...
58
    {
59 1
        if ($violations->count()) {
60
            $data = null;
61
        }
62
63 1
        return new UpdateNodePayload($data, $violations->all(), $inputSource['clientMutationId'] ?? null);
64
    }
65
66
    /**
67
     * @param NodeInterface $node
68
     */
69 1
    protected function preUpdate(NodeInterface $node)
0 ignored issues
show
Unused Code introduced by
The parameter $node is not used and could be removed. ( Ignorable by Annotation )

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

69
    protected function preUpdate(/** @scrutinizer ignore-unused */ NodeInterface $node)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71
        //override
72 1
    }
73
74
    /**
75
     * @param NodeInterface $node
76
     */
77 1
    protected function postUpdate(NodeInterface $node)
0 ignored issues
show
Unused Code introduced by
The parameter $node is not used and could be removed. ( Ignorable by Annotation )

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

77
    protected function postUpdate(/** @scrutinizer ignore-unused */ NodeInterface $node)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
    {
79
        //override
80 1
    }
81
}
82