Completed
Branch master (d2bd5b)
by Dominik
02:06
created

AbstractParentNode   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 19.51 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 3
c 3
b 1
f 0
lcom 1
cbo 1
dl 8
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A setParent() 8 8 2

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
namespace Saxulum\ElasticSearchQueryBuilder\Node;
4
5
abstract class AbstractParentNode extends AbstractNode
6
{
7
    /**
8
     * @var AbstractNode[]|array
9
     */
10
    protected $children = [];
11
12
    /**
13
     * @var boolean
14
     */
15
    protected $allowEmpty;
16
17
    /**
18
     * @var \ReflectionProperty
19
     */
20
    protected $reflectionProperty;
21
22
    /**
23
     * @param boolean $allowEmpty
24
     */
25
    public function __construct($allowEmpty = false)
26
    {
27
        $this->allowEmpty = $allowEmpty;
28
29
        $this->reflectionProperty = new \ReflectionProperty(AbstractNode::classname, 'parent');
30
        $this->reflectionProperty->setAccessible(true);
31
    }
32
33
    /**
34
     * @param AbstractNode $node
35
     * @return void
36
     */
37 View Code Duplication
    protected function setParent(AbstractNode $node)
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...
38
    {
39
        if (null !== $this->reflectionProperty->getValue($node)) {
40
            throw new \InvalidArgumentException('Node already got a parent!');
41
        }
42
43
        $this->reflectionProperty->setValue($node, $this);
44
    }
45
}
46