Completed
Pull Request — master (#52)
by Tom
04:13
created

ApplicationConfigIterator::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace TomPHP\ContainerConfigurator;
4
5
use RecursiveArrayIterator;
6
use RecursiveIteratorIterator;
7
8
final class ApplicationConfigIterator extends RecursiveIteratorIterator
9
{
10
    /**
11
     * @var string[]
12
     */
13
    private $path = [];
14
15
    /**
16
     * @var string
17
     */
18
    private $separator;
19
20
    /**
21
     * @param ApplicationConfig $config
22
     */
23
    public function __construct(ApplicationConfig $config)
24
    {
25
        parent::__construct(
26
            new RecursiveArrayIterator($config->asArray()),
27
            RecursiveIteratorIterator::SELF_FIRST
28
        );
29
        $this->separator = $config->getSeparator();
30
    }
31
32
    public function key()
33
    {
34
        return implode($this->separator, array_merge($this->path, [parent::key()]));
35
    }
36
37
    public function next()
38
    {
39
        if ($this->hasChildren()) {
0 ignored issues
show
Bug introduced by
The method hasChildren() does not exist on TomPHP\ContainerConfigur...plicationConfigIterator. Did you maybe mean callHasChildren()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
40
            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...
41
        }
42
43
        parent::next();
44
    }
45
46
    public function rewind()
47
    {
48
        $this->path = [];
49
50
        parent::rewind();
51
    }
52
53
    public function endChildren()
54
    {
55
        array_pop($this->path);
56
    }
57
}
58