ApplicationConfigIterator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace TomPHP\ContainerConfigurator;
4
5
use RecursiveArrayIterator;
6
use RecursiveIteratorIterator;
7
8
/**
9
 * @internal
10
 */
11
final class ApplicationConfigIterator extends RecursiveIteratorIterator
12
{
13
    /**
14
     * @var string[]
15
     */
16
    private $path = [];
17
18
    /**
19
     * @var string
20
     */
21
    private $separator;
22
23
    /**
24
     * @param ApplicationConfig $config
25
     */
26
    public function __construct(ApplicationConfig $config)
27
    {
28
        parent::__construct(
29
            new RecursiveArrayIterator($config->asArray()),
30
            RecursiveIteratorIterator::SELF_FIRST
31
        );
32
        $this->separator = $config->getSeparator();
33
    }
34
35
    public function key()
36
    {
37
        return implode($this->separator, array_merge($this->path, [parent::key()]));
38
    }
39
40
    public function next()
41
    {
42
        if ($this->callHasChildren()) {
43
            array_push($this->path, parent::key());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (key() instead of next()). Are you sure this is correct? If so, you might want to change this to $this->key().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
44
        }
45
46
        parent::next();
47
    }
48
49
    public function rewind()
50
    {
51
        $this->path = [];
52
53
        parent::rewind();
54
    }
55
56
    public function endChildren()
57
    {
58
        array_pop($this->path);
59
    }
60
}
61