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.

RecursiveSortIterator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 42
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A getSortedIterator() 0 18 4
A hasChildren() 0 4 1
A getChildren() 0 4 1
1
<?php
2
3
namespace Gielfeldt\Iterators;
4
5
class RecursiveSortIterator extends SortIterator implements \RecursiveIterator
6
{
7
    protected $children = [];
8
9 3
    public function __construct(\Traversable $iterator, int $direction = self::SORT_ASC, int $flags = 0, callable $callback = self::SORT_CURRENT)
10
    {
11 3
        $iterator = $iterator instanceof \IteratorAggregate ? $iterator->getIterator() : $iterator;
12 3
        if (!$iterator instanceof \RecursiveIterator) {
13 1
            throw new \InvalidArgumentException('An instance of RecursiveIterator or IteratorAggregate creating it is required');
14
        }
15 2
        parent::__construct($iterator, $direction, $flags, $callback);
16 2
    }
17
18 2
    public function getSortedIterator($iterator)
19
    {
20 2
        $sortedIterator = new \RecursiveArrayIterator();
21 2
        $sorted = [];
22 2
        foreach ($iterator as $key => $value) {
23 2
            if ($iterator->hasChildren()) {
24 2
                $this->children[$key] = $iterator->getChildren();
25
            }
26 2
            $sorted[] = $this->generateElement($key, $value, $iterator);
27
        }
28
29 2
        usort($sorted, $this->realCallback);
30
31 2
        foreach ($sorted as $data) {
32 2
            $sortedIterator->append($data);
33
        }
34 2
        return $sortedIterator;
35
    }
36
37 2
    public function hasChildren()
38
    {
39 2
        return isset($this->children[$this->key()]);
40
    }
41
42 2
    public function getChildren()
43
    {
44 2
        return new self($this->children[$this->key()], $this->direction, $this->flags, $this->callback);
45
    }
46
}
47