GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

NestedKeyIterator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A callGetChildren() 0 5 1
A endChildren() 0 5 1
A key() 0 7 1
1
<?php
2
/**
3
 * This file is part of library-template
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author Nicolò Martini <[email protected]>
9
 */
10
11
namespace StringTemplate;
12
13
14
use RecursiveArrayIterator;
15
16
/**
17
 * Class NestedKeyIterator
18
 *
19
 * This iterator iterates recoursively through an array,
20
 * returning as the current key an imploded list of the stacked keys
21
 * separated by a given separator.
22
 *
23
 * Example:
24
 * <code>
25
 * $ary = [
26
 *      'foo' => 'bar',
27
 *      'baz' => ['foo' => ['uh' => 'ah'], 'oh' => 'eh']
28
 * ]
29
 * foreach (new NestedKeyIterator($ary) as $key => $value) {
30
 *  echo "$key: value\n",
31
 * }
32
 * </code>
33
 * prints
34
 *  foo: bar
35
 *  baz.foo.uh: ah
36
 *  baz.oh: eh
37
 *
38
 * @package StringTemplate
39
 */
40
class NestedKeyIterator extends \RecursiveIteratorIterator
41
{
42
    private $stack = array();
43
    private $keySeparator;
44
45
    /**
46
     * @param \Traversable $iterator
47
     * @param string $separator
48
     * @param int $mode
49
     * @param int $flags
50
     */
51
    public function __construct(\Traversable $iterator, $separator = '.', $mode = \RecursiveIteratorIterator::LEAVES_ONLY, $flags = 0)
52
    {
53
        $this->keySeparator = $separator;
54
        parent::__construct($iterator, $mode, $flags);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function callGetChildren()
61
    {
62
        $this->stack[] = parent::key();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (key() instead of callGetChildren()). 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...
63
        return parent::callGetChildren();
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function endChildren()
70
    {
71
        parent::endChildren();
72
        array_pop($this->stack);
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function key()
79
    {
80
        $keys = $this->stack;
81
        $keys[] = parent::key();
82
83
        return implode($this->keySeparator, $keys);
84
    }
85
}