RemoveSubscriber::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 7
loc 7
rs 9.4286
cc 1
eloc 5
nc 1
nop 2
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\Phpcr;
13
14
use Sulu\Component\DocumentManager\DocumentRegistry;
15
use Sulu\Component\DocumentManager\Event\RemoveEvent;
16
use Sulu\Component\DocumentManager\Events;
17
use Sulu\Component\DocumentManager\NodeManager;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
/**
21
 * Remove subscriber.
22
 */
23 View Code Duplication
class RemoveSubscriber 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
     * @var DocumentRegistry
27
     */
28
    private $documentRegistry;
29
30
    /**
31
     * @var NodeManager
32
     */
33
    private $nodeManager;
34
35
    public function __construct(
36
        DocumentRegistry $documentRegistry,
37
        NodeManager $nodeManager
38
    ) {
39
        $this->documentRegistry = $documentRegistry;
40
        $this->nodeManager = $nodeManager;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public static function getSubscribedEvents()
47
    {
48
        return [
49
            Events::REMOVE => ['handleRemove', 500],
50
        ];
51
    }
52
53
    /**
54
     * Remove the given documents node from PHPCR session and optionally
55
     * remove any references to the node.
56
     *
57
     * @param RemoveEvent $event
58
     */
59
    public function handleRemove(RemoveEvent $event)
60
    {
61
        $document = $event->getDocument();
62
        $node = $this->documentRegistry->getNodeForDocument($document);
63
64
        $node->remove();
65
    }
66
}
67