Passed
Push — develop ( cb60d7...ef7d65 )
by Maarten de
07:14
created

ValuePath::getNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cloudstek\SCIM\FilterParser\AST;
6
7
/**
8
 * Value path.
9
 */
10
class ValuePath extends AbstractNode implements Path
11
{
12
    private AttributePath $attributePath;
13
14
    private ?string $subAttribute;
15
16
    private Node $node;
17
18
    /**
19
     * Value path..
20
     *
21
     * @param AttributePath $attributePath
22
     * @param Node          $node
23
     * @param string|null   $subAttribute
24
     * @param Node|null     $parent
25
     */
26
    public function __construct(
27
        AttributePath $attributePath,
28
        Node $node,
29
        ?string $subAttribute = null,
30
        ?Node $parent = null
31
    ) {
32
        parent::__construct($parent);
33
34
        $this->attributePath = $attributePath;
35
        $this->subAttribute = $subAttribute;
36
37
        $this->node = $node;
38
        $this->node->setParent($this);
39
    }
40
41
    /**
42
     * Get attribute path.
43
     *
44
     * @return AttributePath
45
     */
46
    public function getAttributePath(): AttributePath
47
    {
48
        return $this->attributePath;
49
    }
50
51
    /**
52
     * Get sub attribute.
53
     *
54
     * Paths in PATCH requests can have a value path followed by a sub attribute.
55
     *
56
     * @return string|null
57
     */
58
    public function getSubAttribute(): ?string
59
    {
60
        return $this->subAttribute;
61
    }
62
63
    /**
64
     * Return a new ValuePath with sub attribute.
65
     *
66
     * @param string $subAttribute
67
     *
68
     * @return ValuePath
69
     */
70
    public function withSubAttribute(string $subAttribute): ValuePath
71
    {
72
        $self = clone($this);
73
        $self->subAttribute = $subAttribute;
74
75
        return $self;
76
    }
77
78
    /**
79
     * Get node.
80
     *
81
     * @return Node
82
     */
83
    public function getNode(): Node
84
    {
85
        return $this->node;
86
    }
87
}
88