UpdateNode::onSubmit()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 10
cc 3
nc 2
nop 1
crap 12
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 Symfony\Component\Form\FormEvent;
14
use Ynlo\GraphQLBundle\Exception\Controlled\NotFoundError;
15
use Ynlo\GraphQLBundle\Model\NodeInterface;
16
use Ynlo\GraphQLBundle\Validator\ConstraintViolationList;
17
18
/**
19
 * Class UpdateNodeMutation
20
 */
21
class UpdateNode extends AbstractMutationResolver
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function process(&$data)
27
    {
28
        $this->preUpdate($data);
29
        foreach ($this->extensions as $extension) {
30
            $extension->preUpdate($data, $this, $this->context);
31
        }
32
33
        $this->getManager()->flush();
34
35
        $this->postUpdate($data);
36
        foreach ($this->extensions as $extension) {
37
            $extension->postUpdate($data, $this, $this->context);
38
        }
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function onSubmit(FormEvent $event)
45
    {
46
        if (!$event->getData() instanceof NodeInterface || !$event->getData()->getId()) {
47
            throw new NotFoundError();
48
        }
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function returnPayload($data, ConstraintViolationList $violations, $inputSource)
55
    {
56
        if ($violations->count()) {
57
            $data = null;
58
        }
59
60
        $class = $this->getPayloadClass();
61
62
        return new $class($data, $violations->all(), $inputSource['clientMutationId'] ?? null);
63
    }
64
65
    /**
66
     * @param NodeInterface $node
67
     */
68
    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

68
    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...
69
    {
70
        //override
71
    }
72
73
    /**
74
     * @param NodeInterface $node
75
     */
76
    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

76
    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...
77
    {
78
        //override
79
    }
80
}
81