UuidSubscriber::handleUuid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 16
loc 16
rs 9.4286
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Component\DocumentManager\Subscriber\Behavior\Mapping;
13
14
use Sulu\Component\DocumentManager\Behavior\Mapping\UuidBehavior;
15
use Sulu\Component\DocumentManager\Event\AbstractMappingEvent;
16
use Sulu\Component\DocumentManager\Events;
17
use Sulu\Component\DocumentManager\Exception\DocumentManagerException;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
/**
21
 * Maps the UUID.
22
 */
23 View Code Duplication
class UuidSubscriber implements EventSubscriberInterface
0 ignored issues
show
Duplication introduced by
This class 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...
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public static function getSubscribedEvents()
29
    {
30
        return [
31
            Events::HYDRATE => 'handleUuid',
32
            Events::PERSIST => ['handleUuid', 0],
33
        ];
34
    }
35
36
    /**
37
     * @param AbstractMappingEvent $event
38
     *
39
     * @throws DocumentManagerException
40
     */
41
    public function handleUuid(AbstractMappingEvent $event)
42
    {
43
        $document = $event->getDocument();
44
45
        if (!$document instanceof UuidBehavior) {
46
            return;
47
        }
48
49
        $node = $event->getNode();
50
51
        $accessor = $event->getAccessor();
52
        $accessor->set(
53
            'uuid',
54
            $node->getIdentifier()
55
        );
56
    }
57
}
58