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

AddNode   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 50 %

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
dl 23
loc 46
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A postPersist() 0 2 1
A returnPayload() 7 7 2
A prePersist() 0 2 1
A process() 13 13 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\Extension\ExtensionManager;
14
use Ynlo\GraphQLBundle\Model\AddNodePayload;
15
use Ynlo\GraphQLBundle\Model\NodeInterface;
16
use Ynlo\GraphQLBundle\Validator\ConstraintViolationList;
17
18
/**
19
 * Class AddNode
20
 */
21
class AddNode extends AbstractMutationResolver
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 4 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...
27
    {
28 4
        $this->prePersist($data);
29 4
        foreach ($this->container->get(ExtensionManager::class)->getExtensions() as $extension) {
30
            $extension->prePersist($data, $this, $this->context);
31
        }
32
33 4
        $this->getManager()->persist($data);
34 4
        $this->getManager()->flush();
35
36 4
        $this->postPersist($data);
37 4
        foreach ($this->container->get(ExtensionManager::class)->getExtensions() as $extension) {
38
            $extension->postPersist($data, $this, $this->context);
39
        }
40 4
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 5 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...
46
    {
47 5
        if ($violations->count()) {
48 1
            $data = null;
49
        }
50
51 5
        return new AddNodePayload($data, $violations->all(), $inputSource['clientMutationId'] ?? null);
52
    }
53
54
    /**
55
     * @param NodeInterface $node
56
     */
57 4
    protected function prePersist(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

57
    protected function prePersist(/** @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...
58
    {
59
        //override
60 4
    }
61
62
    /**
63
     * @param NodeInterface $node
64
     */
65 4
    protected function postPersist(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

65
    protected function postPersist(/** @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...
66
    {
67
        //override
68 4
    }
69
}
70