Completed
Pull Request — master (#28)
by Tom
02:23
created

ConfigIterator::endChildren()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace TomPHP\ConfigServiceProvider;
4
5
use RecursiveArrayIterator;
6
use RecursiveIteratorIterator;
7
8
final class ConfigIterator extends RecursiveIteratorIterator
9
{
10
    /**
11
     * @var string[]
12
     */
13
    private $path = [];
14
15
    /**
16
     * @var string
17
     */
18
    private $separator;
19
20
    /**
21
     * @param Config $config
22
     */
23
    public function __construct(Config $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\ConfigServiceProvider\ConfigIterator. 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