Completed
Pull Request — master (#43)
by Jose Manuel
02:54
created

CollectionIterator::hasChildren()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 7
cp 0.8571
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 3.0261
1
<?php
2
3
namespace Softonic\GraphQL\DataObjects;
4
5
class CollectionIterator extends \RecursiveArrayIterator
6
{
7 78
    public function valid(): bool
8
    {
9 78
        $isValid = parent::valid();
10 78
        if ($isValid && !$this->hasChildren() && $this->current() instanceof AbstractCollection) {
11 2
            $this->next();
12
13 2
            return $this->valid();
14
        }
15
16 78
        return $isValid;
17
    }
18
19 76
    public function hasChildren(): bool
20
    {
21 76
        $current = $this->current();
22 76
        if ($current instanceof AbstractItem) {
23 76
            return false;
24
        }
25
26 6
        if (is_array($current)) {
27
            return true;
28
        }
29
30 6
        return $current->hasChildren();
31
    }
32
33 6
    public function getChildren()
34
    {
35 6
        return parent::current()->getIterator()->getInnerIterator();
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...
36
    }
37
}
38