JoinColumn   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 204
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 17
c 5
b 1
f 2
lcom 4
cbo 1
dl 0
loc 204
ccs 44
cts 44
cp 1
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A target() 0 4 1
A source() 0 4 1
A getJoinColumn() 0 4 2
A getReferenceColumn() 0 4 2
A isNullable() 0 4 1
A isUnique() 0 4 1
A getOnDelete() 0 4 1
A __construct() 0 17 1
A foreignKey() 0 6 1
A localKey() 0 6 1
A setJoinColumn() 0 6 1
A setReferenceColumn() 0 6 1
A nullable() 0 6 1
A unique() 0 6 1
A onDelete() 0 6 1
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Relations;
4
5
use Doctrine\ORM\Mapping\NamingStrategy;
6
7
class JoinColumn
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $relation;
13
14
    /**
15
     * @var string
16
     */
17
    protected $joinColumn;
18
19
    /**
20
     * @var string
21
     */
22
    protected $referenceColumn;
23
24
    /**
25
     * @var bool
26
     */
27
    protected $nullable = true;
28
29
    /**
30
     * @var bool
31
     */
32
    protected $unique = false;
33
34
    /**
35
     * @var string|null
36
     */
37
    protected $onDelete = null;
38
39
    /**
40
     * @var NamingStrategy
41
     */
42
    protected $namingStrategy;
43
44
    /**
45
     * @param NamingStrategy $namingStrategy
46
     * @param string         $relation
47
     * @param string|null    $joinColumn
48
     * @param string|null    $referenceColumn
49
     * @param bool           $nullable
50
     * @param bool           $unique
51
     * @param string|null    $onDelete
52
     */
53 67
    public function __construct(
54
        NamingStrategy $namingStrategy,
55
        $relation,
56
        $joinColumn = null,
57
        $referenceColumn = null,
58
        $nullable = true,
59
        $unique = false,
60
        $onDelete = null
61
    ) {
62 67
        $this->joinColumn       = $joinColumn;
63 67
        $this->referenceColumn  = $referenceColumn;
64 67
        $this->relation         = $relation;
65 67
        $this->namingStrategy   = $namingStrategy;
66 67
        $this->nullable         = $nullable;
67 67
        $this->onDelete         = $onDelete;
68 67
        $this->unique           = $unique;
69 67
    }
70
71
    /**
72
     * @param string $foreignKey
73
     *
74
     * @return $this
75
     */
76 4
    public function foreignKey($foreignKey)
77
    {
78 4
        $this->joinColumn = $foreignKey;
79
80 4
        return $this;
81
    }
82
83
    /**
84
     * @param string $foreignKey
85
     *
86
     * @return $this
87
     */
88 3
    public function target($foreignKey)
89
    {
90 3
        return $this->foreignKey($foreignKey);
91
    }
92
93
    /**
94
     * @param string $localKey
95
     *
96
     * @return $this
97
     */
98 4
    public function localKey($localKey)
99
    {
100 4
        $this->referenceColumn = $localKey;
101
102 4
        return $this;
103
    }
104
105
    /**
106
     * @param string $localKey
107
     *
108
     * @return $this
109
     */
110 3
    public function source($localKey)
111
    {
112 3
        return $this->localKey($localKey);
113
    }
114
115
    /**
116
     * @return string
117
     */
118 48
    public function getJoinColumn()
119
    {
120 48
        return $this->joinColumn ?: $this->namingStrategy->joinColumnName($this->relation);
121
    }
122
123
    /**
124
     * @param string $joinColumn
125
     *
126
     * @return $this
127
     */
128 1
    public function setJoinColumn($joinColumn)
129
    {
130 1
        $this->joinColumn = $joinColumn;
131
132 1
        return $this;
133
    }
134
135
    /**
136
     * @return string
137
     */
138 48
    public function getReferenceColumn()
139
    {
140 48
        return $this->referenceColumn ?: $this->namingStrategy->referenceColumnName();
141
    }
142
143
    /**
144
     * @param string $referenceColumn
145
     *
146
     * @return $this
147
     */
148 1
    public function setReferenceColumn($referenceColumn)
149
    {
150 1
        $this->referenceColumn = $referenceColumn;
151
152 1
        return $this;
153
    }
154
155
    /**
156
     * @return $this
157
     */
158 2
    public function nullable()
159
    {
160 2
        $this->nullable = true;
161
162 2
        return $this;
163
    }
164
165
    /**
166
     * @return bool
167
     */
168 46
    public function isNullable()
169
    {
170 46
        return $this->nullable;
171
    }
172
173
    /**
174
     * @return bool
175
     */
176 46
    public function isUnique()
177
    {
178 46
        return $this->unique;
179
    }
180
181
    /**
182
     * @return $this
183
     */
184 2
    public function unique()
185
    {
186 2
        $this->unique = true;
187
188 2
        return $this;
189
    }
190
191
    /**
192
     * @return string|null
193
     */
194 46
    public function getOnDelete()
195
    {
196 46
        return $this->onDelete;
197
    }
198
199
    /**
200
     * @param string|null $onDelete
201
     *
202
     * @return $this
203
     */
204 2
    public function onDelete($onDelete = null)
205
    {
206 2
        $this->onDelete = $onDelete;
207
208 2
        return $this;
209
    }
210
}
211