Completed
Branch master (343030)
by Dominik
05:26 queued 02:33
created

ArrayNode   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 17
Bugs 3 Features 3
Metric Value
wmc 8
c 17
b 3
f 3
lcom 1
cbo 2
dl 0
loc 57
ccs 22
cts 22
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 9 1
A getDefault() 0 4 1
A serialize() 0 13 3
A serializeChild() 0 8 3
1
<?php
2
3
namespace Saxulum\ElasticSearchQueryBuilder\Node;
4
5
class ArrayNode extends AbstractParentNode
6
{
7
    /**
8
     * @param AbstractNode $node
9
     * @param bool         $allowDefault
10
     *
11
     * @return $this
12
     */
13 4
    public function add(AbstractNode $node, $allowDefault = false)
14
    {
15 4
        $node->setParent($this);
16
17 4
        $this->children[] = $node;
18 4
        $this->allowDefault[] = $allowDefault;
19
20 4
        return $this;
21
    }
22
23
    /**
24
     * @return array
25
     */
26 1
    public function getDefault()
27
    {
28 1
        return [];
29
    }
30
31
    /**
32
     * @return \stdClass|null
33
     */
34 4
    public function serialize()
35
    {
36 4
        $serialized = [];
37 4
        foreach ($this->children as $i => $child) {
38 3
            $this->serializeChild($serialized, $i, $child);
39 4
        }
40
41 4
        if ([] === $serialized) {
42 2
            return;
43
        }
44
45 2
        return $serialized;
46
    }
47
48
    /**
49
     * @param array        $serialized
50
     * @param string       $name
0 ignored issues
show
Bug introduced by
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
51
     * @param AbstractNode $child
52
     */
53 3
    private function serializeChild(array &$serialized, $i, AbstractNode $child)
54
    {
55 3
        if (null !== $serializedChild = $child->serialize()) {
56 1
            $serialized[] = $serializedChild;
57 3
        } elseif ($this->allowDefault[$i]) {
58 1
            $serialized[] = $child->getDefault();
59 1
        }
60 3
    }
61
}
62