Passed
Push — master ( ee214c...3dfb16 )
by Rafael
04:03
created

AddNode   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A postPersist() 0 2 1
A prePersist() 0 2 1
A returnPayload() 0 7 2
A process() 0 13 3
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 5
    public function process(&$data)
27
    {
28 5
        $this->prePersist($data);
29 5
        foreach ($this->extensions as $extension) {
30 4
            $extension->prePersist($data, $this, $this->context);
31
        }
32
33 5
        $this->getManager()->persist($data);
34 5
        $this->getManager()->flush();
35
36 5
        $this->postPersist($data);
37 5
        foreach ($this->extensions as $extension) {
38 4
            $extension->postPersist($data, $this, $this->context);
39
        }
40 5
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 6
    public function returnPayload($data, ConstraintViolationList $violations, $inputSource)
46
    {
47 6
        if ($violations->count()) {
48 1
            $data = null;
49
        }
50
51 6
        return new AddNodePayload($data, $violations->all(), $inputSource['clientMutationId'] ?? null);
52
    }
53
54
    /**
55
     * @param NodeInterface $node
56
     */
57 5
    protected function prePersist(NodeInterface $node)
58
    {
59
        //override
60 5
    }
61
62
    /**
63
     * @param NodeInterface $node
64
     */
65 5
    protected function postPersist(NodeInterface $node)
66
    {
67
        //override
68 5
    }
69
}
70