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

DocumentPath   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 14.63%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 57
ccs 6
cts 41
cp 0.1463
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getIndex() 0 4 1
A getType() 0 4 1
A getId() 0 4 1
A getParent() 0 4 1
A getPath() 0 14 4
A isValid() 0 4 3
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