RemoveSubscriber   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 1 Features 1
Metric Value
c 6
b 1
f 1
dl 44
loc 44
wmc 3
lcom 1
cbo 2
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A getSubscribedEvents() 6 6 1
A handleRemove() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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