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

DeleteNode::process()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3.0987

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 1
dl 13
loc 13
ccs 7
cts 9
cp 0.7778
crap 3.0987
rs 9.4285
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\Mutation;
12
13
use Ynlo\GraphQLBundle\Error\NodeNotFoundException;
14
use Ynlo\GraphQLBundle\Extension\ExtensionManager;
15
use Ynlo\GraphQLBundle\Model\DeleteNodePayload;
16
use Ynlo\GraphQLBundle\Model\ID;
17
use Ynlo\GraphQLBundle\Model\NodeInterface;
18
use Ynlo\GraphQLBundle\Validator\ConstraintViolationList;
19
20
/**
21
 * Class DeleteNodeMutation
22
 */
23
class DeleteNode extends AbstractMutationResolver
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 2 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...
29
    {
30 2
        $this->preDelete($data);
31 2
        foreach ($this->container->get(ExtensionManager::class)->getExtensions() as $extension) {
32
            $extension->preDelete($data, $this, $this->context);
33
        }
34
35 2
        $this->getManager()->remove($data);
36 2
        $this->getManager()->flush();
37
38 2
        $this->postDelete($data);
39 2
        foreach ($this->container->get(ExtensionManager::class)->getExtensions() as $extension) {
40
            $extension->postDelete($data, $this, $this->context);
41
        }
42 2
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 2
    protected function returnPayload($data, ConstraintViolationList $violations, $inputSource)
48
    {
49 2
        return new DeleteNodePayload(
50 2
            $inputSource['id'] ? ID::createFromString($inputSource['id']) : null,
0 ignored issues
show
Bug introduced by
It seems like $inputSource['id'] ? Ynl...putSource['id']) : null can also be of type null; however, parameter $id of Ynlo\GraphQLBundle\Model...ePayload::__construct() does only seem to accept Ynlo\GraphQLBundle\Model\ID, maybe add an additional type check? ( Ignorable by Annotation )

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

50
            /** @scrutinizer ignore-type */ $inputSource['id'] ? ID::createFromString($inputSource['id']) : null,
Loading history...
51 2
            $inputSource['clientMutationId'] ?? null
52
        );
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 2
    protected function onSubmit($inputSource, &$normData)
59
    {
60 2
        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...
61 2
            return;
62
        }
63
64
        throw new NodeNotFoundException();
65
    }
66
67
    /**
68
     * @param NodeInterface $node
69
     */
70 2
    protected function preDelete(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

70
    protected function preDelete(/** @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...
71
    {
72
        //override
73 2
    }
74
75
    /**
76
     * @param NodeInterface $node
77
     */
78 2
    protected function postDelete(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

78
    protected function postDelete(/** @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...
79
    {
80
        //override
81 2
    }
82
}
83