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