Completed
Pull Request — master (#45)
by Jose Manuel
02:24
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
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