Completed
Push — master ( be5d10...3892c2 )
by Sergey
07:31
created

DocumentPath::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1.0028

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 7
cp 0.8571
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
crap 1.0028
1
<?php
2
3
namespace Isswp101\Persimmon\Elasticsearch;
4
5
use Isswp101\Persimmon\Traits\Presentable;
6
7
class DocumentPath
8
{
9
    use Presentable;
10
11
    public $index;
12
    public $type;
13
    public $id;
14
    public $parent;
15
16 17
    public function __construct($index, $type, $id, $parent = null)
17
    {
18 17
        $this->index = $index;
19 17
        $this->type = $type;
20 17
        $this->id = $id;
21 17
        $this->parent = $parent;
22 17
    }
23
24
    public function getIndex()
25
    {
26
        return $this->index;
27
    }
28
29
    public function getType()
30
    {
31
        return $this->type;
32
    }
33
34
    public function getId()
35
    {
36
        return $this->id;
37
    }
38
39
    public function getParent()
40
    {
41
        return $this->parent;
42
    }
43
44
    public function getPath()
45
    {
46
        $res = [];
47
        if (!is_null($this->index)) {
48
            $res[] = $this->index;
49
        }
50
        if (!is_null($this->type)) {
51
            $res[] = $this->type;
52
        }
53
        if (!is_null($this->id)) {
54
            $res[] = $this->id;
55
        }
56
        return implode('/', $res);
57
    }
58
59
    public function isValid()
60
    {
61
        return $this->index && $this->type && $this->id;
62
    }
63
}
64