PersistEvent   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 91
Duplicated Lines 26.37 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 9
Bugs 2 Features 3
Metric Value
c 9
b 2
f 3
dl 24
loc 91
wmc 10
lcom 1
cbo 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getDebugMessage() 0 8 2
A setNode() 0 4 1
A setParentNode() 0 4 1
A getNode() 12 12 2
A getParentNode() 12 12 2
A hasParentNode() 0 4 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\Event;
13
14
use PHPCR\NodeInterface;
15
use Sulu\Component\DocumentManager\DocumentHelper;
16
17
class PersistEvent extends AbstractMappingEvent
18
{
19
    /**
20
     * @param NodeInterface
21
     */
22
    private $parentNode;
23
24
    /**
25
     * @param object $document
26
     * @param string $locale
27
     * @param array $options
28
     */
29
    public function __construct($document, $locale, array $options = [])
30
    {
31
        $this->document = $document;
32
        $this->locale = $locale;
33
        $this->options = $options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options of type array is incompatible with the declared type object<Symfony\Component...solver\OptionsResolver> of property $options.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getDebugMessage()
40
    {
41
        return sprintf(
42
            '%s p:%s',
43
            parent::getDebugMessage(),
44
            $this->parentNode ? $this->parentNode->getPath() : '<no parent node>'
45
        );
46
    }
47
48
    /**
49
     * @param NodeInterface $node
50
     */
51
    public function setNode(NodeInterface $node)
52
    {
53
        $this->node = $node;
54
    }
55
56
    /**
57
     * @param NodeInterface $parentNode
58
     */
59
    public function setParentNode(NodeInterface $parentNode)
60
    {
61
        $this->parentNode = $parentNode;
62
    }
63
64
    /**
65
     * @return NodeInterface
66
     *
67
     * @throws \RuntimeException
68
     */
69 View Code Duplication
    public function getNode()
0 ignored issues
show
Duplication introduced by
This method 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...
70
    {
71
        if (!$this->node) {
72
            throw new \RuntimeException(sprintf(
73
                'Trying to retrieve node when no node has been set. An event ' .
74
                'listener should have set the node when persisting document "%s"',
75
                DocumentHelper::getDebugTitle($this->document)
76
            ));
77
        }
78
79
        return $this->node;
80
    }
81
82
    /**
83
     * @return NodeInterface
84
     *
85
     * @throws \RuntimeException
86
     */
87 View Code Duplication
    public function getParentNode()
0 ignored issues
show
Duplication introduced by
This method 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...
88
    {
89
        if (!$this->parentNode) {
90
            throw new \RuntimeException(sprintf(
91
                'Trying to retrieve parent node when no parent node has been set. An event ' .
92
                'listener should have set the node when persisting document "%s"',
93
                DocumentHelper::getDebugTitle($this->document)
94
            ));
95
        }
96
97
        return $this->parentNode;
98
    }
99
100
    /**
101
     * @return bool
102
     */
103
    public function hasParentNode()
104
    {
105
        return $this->parentNode !== null;
106
    }
107
}
108