Completed
Branch master (a93247)
by Dominik
04:14 queued 01:56
created

ArrayNode::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Saxulum\ElasticSearchQueryBuilder\Node;
4
5
class ArrayNode extends AbstractParentNode
6
{
7
    /**
8
     * @param AbstractNode $node
9
     * @return $this
10
     */
11
    public function add(AbstractNode $node)
12
    {
13
        if (null !== $this->reflectionProperty->getValue($node)) {
14
            throw new \InvalidArgumentException('Node already got a parent!');
15
        }
16
17
        $this->reflectionProperty->setValue($node, $this);
18
19
        $this->children[] = $node;
20
21
        return $this;
22
    }
23
24
    /**
25
     * @return array|null
26
     */
27
    public function serialize()
28
    {
29
        $serialized = [];
30 View Code Duplication
        foreach ($this->children as $child) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
31
            if (null !== $serializedChild = $child->serialize()) {
32
                $serialized[] = $serializedChild;
33
            }
34
        }
35
36
        if (!$this->allowEmpty && [] === $serialized) {
37
            return null;
38
        }
39
40
        return $serialized;
41
    }
42
}
43