Passed
Push — master ( 099732...be2242 )
by Christopher
02:03
created

SyncRelationship::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Triadev\Leopard\Model;
3
4
class SyncRelationship
5
{
6
    /** @var string */
7
    private $relatedClass;
8
    
9
    /** @var string */
10
    private $foreignKey;
11
    
12
    /** @var string|null */
13
    private $ownerKey;
14
    
15
    /** @var string|null */
16
    private $relation;
17
    
18
    /**
19
     * SyncRelationship constructor.
20
     * @param string $relatedClass
21
     */
22 2
    public function __construct(string $relatedClass)
23
    {
24 2
        $this->relatedClass = $relatedClass;
25 2
    }
26
    
27
    /**
28
     * @param string $relatedClass
29
     * @return SyncRelationship
30
     */
31 2
    public static function create(string $relatedClass) : SyncRelationship
32
    {
33 2
        $class = get_called_class();
34 2
        return new $class($relatedClass);
35
    }
36
    
37
    /**
38
     * @return string
39
     */
40 2
    public function getRelatedClass(): string
41
    {
42 2
        return $this->relatedClass;
43
    }
44
    
45
    /**
46
     * Foreign key
47
     *
48
     * @param string $foreignKey
49
     * @return SyncRelationship
50
     */
51 1
    public function foreignKey(string $foreignKey) : SyncRelationship
52
    {
53 1
        $this->foreignKey = $foreignKey;
54 1
        return $this;
55
    }
56
    
57
    /**
58
     * Get foreign key
59
     *
60
     * @return string
61
     */
62 2
    public function getForeignKey() : ?string
63
    {
64 2
        return $this->foreignKey ?: (new $this->relatedClass())->getForeignKey();
65
    }
66
    
67
    /**
68
     * Owner key
69
     *
70
     * @param string $ownerKey
71
     * @return SyncRelationship
72
     */
73 1
    public function ownerKey(string $ownerKey) : SyncRelationship
74
    {
75 1
        $this->ownerKey = $ownerKey;
76 1
        return $this;
77
    }
78
    
79
    /**
80
     * @return string|null
81
     */
82 2
    public function getOwnerKey(): ?string
83
    {
84 2
        return $this->ownerKey;
85
    }
86
    
87
    /**
88
     * Relation
89
     *
90
     * @param string $relation
91
     * @return SyncRelationship
92
     */
93
    public function relation(string $relation) : SyncRelationship
94
    {
95
        $this->relation = $relation;
96
        return $this;
97
    }
98
    
99
    /**
100
     * @return string|null
101
     */
102 2
    public function getRelation(): ?string
103
    {
104 2
        return $this->relation;
105
    }
106
}
107