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

AbstractParentNode::setParent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
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