Passed
Push — master ( 5522e6...cb60d7 )
by Maarten de
03:38 queued 01:47
created

AbstractNode::hasParent()   B

Complexity

Conditions 8
Paths 9

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 10
nc 9
nop 2
dl 0
loc 19
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cloudstek\SCIM\FilterParser\AST;
6
7
/**
8
 * Abstract node.
9
 */
10
abstract class AbstractNode implements Node
11
{
12
    protected ?Node $parent = null;
13
14
    /**
15
     * Abstract node.
16
     *
17
     * @param Node|null $parent
18
     */
19
    public function __construct(?Node $parent = null)
20
    {
21
        $this->parent = $parent;
22
    }
23
24
    /**
25
     * @inheritDoc
26
     */
27
    public function getParent(): ?Node
28
    {
29
        return $this->parent;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35
    public function setParent(?Node $node): self
36
    {
37
        $this->parent = $node;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45
    public function hasParent($parent = null, bool $recursive = false): bool
46
    {
47
        if ($parent === null) {
48
            return $this->parent !== null;
49
        }
50
51
        $foundParent = false;
52
53
        if ($parent instanceof Node) {
54
            $foundParent = $this->parent === $parent;
55
        } elseif (is_string($parent)) {
56
            $foundParent = isset($this->parent) && get_class($this->parent) === $parent;
57
        }
58
59
        if ($recursive === true && isset($this->parent) && $foundParent === false) {
60
            return $this->parent->hasParent($parent, true);
1 ignored issue
show
Bug introduced by
The method hasParent() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
            return $this->parent->/** @scrutinizer ignore-call */ hasParent($parent, true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
        }
62
63
        return $foundParent;
64
    }
65
}
66