Completed
Pull Request — master (#45)
by Jose Manuel
02:24
created

CollectionIterator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 35
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A valid() 0 11 4
A hasChildren() 0 13 3
A getChildren() 0 6 1
1
<?php
2
3
namespace Softonic\GraphQL\DataObjects;
4
5
use RecursiveArrayIterator;
6
7
class CollectionIterator extends RecursiveArrayIterator
8
{
9 82
    public function valid(): bool
10
    {
11 82
        $isValid = parent::valid();
12 82
        if ($isValid && !$this->hasChildren() && $this->current() instanceof AbstractCollection) {
13 2
            $this->next();
14
15 2
            return $this->valid();
16
        }
17
18 82
        return $isValid;
19
    }
20
21 80
    public function hasChildren(): bool
22
    {
23 80
        $current = $this->current();
24 80
        if ($current instanceof AbstractItem) {
25 80
            return false;
26
        }
27
28 6
        if (is_array($current)) {
29
            return true;
30
        }
31
32 6
        return $current->hasChildren();
33
    }
34
35 6
    public function getChildren()
36
    {
37 6
        return parent::current()
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (current() instead of getChildren()). Are you sure this is correct? If so, you might want to change this to $this->current().

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...
38 6
            ->getIterator()
39 6
            ->getInnerIterator();
40
    }
41
}
42