Completed
Pull Request — master (#22)
by Sergey
14:20
created

RelationshipKey::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Isswp101\Persimmon\Relationship;
4
5
class RelationshipKey
6
{
7
    const DELIMITER = ':';
8
9
    private $id;
10
    private $parentId;
11
12
    public function __construct(string $id, string $parentId = null)
13
    {
14
        $this->id = $id;
15
        $this->parentId = $parentId;
16
    }
17
18
    public function getId(): string
19
    {
20
        return $this->id;
21
    }
22
23
    public function getParentId()
24
    {
25
        return $this->parentId;
26
    }
27
28
    public function build(): string
29
    {
30
        $id = $this->getId();
31
        return $this->getParentId() != null ? $id . RelationshipKey::DELIMITER . $this->getParentId() : $id;
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $this->getParentId() of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
32
    }
33
34
    public static function parse(string $key): RelationshipKey
35
    {
36
        $ids = explode(RelationshipKey::DELIMITER, $key);
37
        return new RelationshipKey($ids[0] ?? null, $ids[1] ?? null);
38
    }
39
}