Completed
Push — master ( c87449...b1fa0d )
by Milos
01:47
created

Path::fromAttributePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the tmilos/scim-filter-parser package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Tmilos\ScimFilterParser\Ast;
13
14
class Path extends Node
15
{
16
    /** @var AttributePath */
17
    private $attributePath;
18
19
    /** @var ValuePath */
20
    private $valuePath;
21
22
    /**
23
     * @param AttributePath $attributePath
24
     *
25
     * @return Path
26
     */
27
    public static function fromAttributePath(AttributePath $attributePath)
28
    {
29
        return new static($attributePath, null);
30
    }
31
32
    /**
33
     * @param ValuePath          $valuePath
34
     * @param AttributePath|null $attributePath
35
     *
36
     * @return Path
37
     */
38
    public static function fromValuePath(ValuePath $valuePath, AttributePath $attributePath = null)
39
    {
40
        return new static($attributePath, $valuePath);
41
    }
42
43
    /**
44
     * @param AttributePath $attributePath
45
     * @param ValuePath     $valuePath
46
     */
47
    private function __construct(AttributePath $attributePath = null, ValuePath $valuePath = null)
48
    {
49
        $this->attributePath = $attributePath;
50
        $this->valuePath = $valuePath;
51
    }
52
53
    public function dump()
54
    {
55
        if (!$this->valuePath) {
56
            return [
57
                'Path' => $this->attributePath->dump(),
58
            ];
59
        } elseif (!$this->attributePath) {
60
            return [
61
                'Path' => $this->valuePath->dump(),
62
            ];
63
        } else {
64
            return array_merge($this->valuePath->dump(), $this->attributePath->dump());
65
        }
66
    }
67
}
68