NodeNameSubscriber::handleNodeName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 15
loc 15
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\NodeNameBehavior;
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 node name.
22
 */
23 View Code Duplication
class NodeNameSubscriber 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 => 'handleNodeName',
32
            Events::PERSIST => 'handleNodeName',
33
        ];
34
    }
35
36
    /**
37
     * @param AbstractMappingEvent $event
38
     *
39
     * @throws DocumentManagerException
40
     */
41
    public function handleNodeName(AbstractMappingEvent $event)
42
    {
43
        $document = $event->getDocument();
44
45
        if (!$document instanceof NodeNameBehavior) {
46
            return;
47
        }
48
49
        $node = $event->getNode();
50
        $accessor = $event->getAccessor();
51
        $accessor->set(
52
            'nodeName',
53
            $node->getName()
54
        );
55
    }
56
}
57