These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\NodeBundle\Entity; |
||
4 | |||
5 | use DateTime; |
||
6 | use Doctrine\ORM\EntityManager; |
||
7 | use Doctrine\ORM\Mapping as ORM; |
||
8 | use Kunstmaan\AdminBundle\Entity\AbstractEntity; |
||
9 | use Kunstmaan\UtilitiesBundle\Helper\ClassLookup; |
||
10 | |||
11 | /** |
||
12 | * NodeVersion |
||
13 | * |
||
14 | * @ORM\Entity(repositoryClass="Kunstmaan\NodeBundle\Repository\NodeVersionRepository") |
||
15 | * @ORM\Table(name="kuma_node_versions", indexes={@ORM\Index(name="idx_node_version_lookup", columns={"ref_id", "ref_entity_name"})}) |
||
16 | * @ORM\HasLifecycleCallbacks() |
||
17 | * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") |
||
18 | */ |
||
19 | class NodeVersion extends AbstractEntity |
||
20 | { |
||
21 | const DRAFT_VERSION = 'draft'; |
||
22 | const PUBLIC_VERSION = 'public'; |
||
23 | |||
24 | /** |
||
25 | * @var NodeTranslation |
||
26 | * |
||
27 | * @ORM\ManyToOne(targetEntity="NodeTranslation", inversedBy="nodeVersions") |
||
28 | * @ORM\JoinColumn(name="node_translation_id", referencedColumnName="id") |
||
29 | */ |
||
30 | protected $nodeTranslation; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | * |
||
35 | * @ORM\Column(type="string") |
||
36 | */ |
||
37 | protected $type; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | * |
||
42 | * @ORM\Column(type="string") |
||
43 | */ |
||
44 | protected $owner; |
||
45 | |||
46 | /** |
||
47 | * @var \DateTime |
||
48 | * |
||
49 | * @ORM\Column(type="datetime") |
||
50 | */ |
||
51 | protected $created; |
||
52 | |||
53 | /** |
||
54 | * @var \DateTime |
||
55 | * |
||
56 | * @ORM\Column(type="datetime") |
||
57 | */ |
||
58 | protected $updated; |
||
59 | |||
60 | /** |
||
61 | * @var int |
||
62 | * |
||
63 | * @ORM\Column(type="bigint", name="ref_id") |
||
64 | */ |
||
65 | protected $refId; |
||
66 | |||
67 | /** |
||
68 | * @var string |
||
69 | * |
||
70 | * @ORM\Column(type="string", name="ref_entity_name") |
||
71 | */ |
||
72 | protected $refEntityName; |
||
73 | |||
74 | /** |
||
75 | * The nodeVersion this nodeVersion originated from |
||
76 | * |
||
77 | * @var NodeVersion |
||
78 | * |
||
79 | * @ORM\ManyToOne(targetEntity="NodeVersion") |
||
80 | * @ORM\JoinColumn(name="origin_id", referencedColumnName="id") |
||
81 | */ |
||
82 | protected $origin; |
||
83 | |||
84 | /** |
||
85 | * Constructor |
||
86 | */ |
||
87 | 33 | public function __construct() |
|
88 | { |
||
89 | 33 | $this->setCreated(new DateTime()); |
|
90 | 33 | $this->setUpdated(new DateTime()); |
|
91 | 33 | } |
|
92 | |||
93 | /** |
||
94 | * Set nodeTranslation |
||
95 | * |
||
96 | * @return NodeVersion |
||
97 | */ |
||
98 | 10 | public function setNodeTranslation(NodeTranslation $nodeTranslation) |
|
99 | { |
||
100 | 10 | $this->nodeTranslation = $nodeTranslation; |
|
101 | |||
102 | 10 | return $this; |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * Get NodeTranslation |
||
107 | * |
||
108 | * @return NodeTranslation |
||
109 | */ |
||
110 | 7 | public function getNodeTranslation() |
|
111 | { |
||
112 | 7 | return $this->nodeTranslation; |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Get type |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | 5 | public function getType() |
|
121 | { |
||
122 | 5 | return $this->type; |
|
123 | } |
||
124 | |||
125 | 6 | public function isDraft() |
|
126 | { |
||
127 | 6 | return self::DRAFT_VERSION === $this->type; |
|
128 | } |
||
129 | |||
130 | 1 | public function isPublic() |
|
131 | { |
||
132 | 1 | return self::PUBLIC_VERSION === $this->type; |
|
133 | } |
||
134 | |||
135 | /** |
||
136 | * Set type |
||
137 | * |
||
138 | * @param string $type |
||
139 | * |
||
140 | * @return NodeVersion |
||
141 | */ |
||
142 | 18 | public function setType($type) |
|
143 | { |
||
144 | 18 | $this->type = $type; |
|
145 | |||
146 | 18 | return $this; |
|
147 | } |
||
148 | |||
149 | /** |
||
150 | * Set owner |
||
151 | * |
||
152 | * @param string $owner |
||
153 | * |
||
154 | * @return NodeVersion |
||
155 | */ |
||
156 | 1 | public function setOwner($owner) |
|
157 | { |
||
158 | 1 | $this->owner = $owner; |
|
159 | |||
160 | 1 | return $this; |
|
161 | } |
||
162 | |||
163 | /** |
||
164 | * Get owner |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | 1 | public function getOwner() |
|
169 | { |
||
170 | 1 | return $this->owner; |
|
171 | } |
||
172 | |||
173 | /** |
||
174 | * Set created |
||
175 | * |
||
176 | * @return NodeVersion |
||
177 | */ |
||
178 | 29 | public function setCreated(DateTime $created) |
|
179 | { |
||
180 | 29 | $this->created = $created; |
|
181 | |||
182 | 29 | return $this; |
|
183 | } |
||
184 | |||
185 | /** |
||
186 | * Get created |
||
187 | * |
||
188 | * @return DateTime |
||
189 | */ |
||
190 | 2 | public function getCreated() |
|
191 | { |
||
192 | 2 | return $this->created; |
|
193 | } |
||
194 | |||
195 | /** |
||
196 | * Set updated |
||
197 | * |
||
198 | * @return NodeVersion |
||
199 | */ |
||
200 | 29 | public function setUpdated(DateTime $updated) |
|
201 | { |
||
202 | 29 | $this->updated = $updated; |
|
203 | |||
204 | 29 | return $this; |
|
205 | } |
||
206 | |||
207 | /** |
||
208 | * Get updated |
||
209 | * |
||
210 | * @return DateTime |
||
211 | */ |
||
212 | 1 | public function getUpdated() |
|
213 | { |
||
214 | 1 | return $this->updated; |
|
215 | } |
||
216 | |||
217 | /** |
||
218 | * Get refId |
||
219 | * |
||
220 | * @return int |
||
221 | */ |
||
222 | 3 | public function getRefId() |
|
223 | { |
||
224 | 3 | return $this->refId; |
|
225 | } |
||
226 | |||
227 | /** |
||
228 | * Set refId |
||
229 | * |
||
230 | * @param int $refId |
||
231 | * |
||
232 | * @return NodeVersion |
||
233 | */ |
||
234 | 8 | protected function setRefId($refId) |
|
235 | { |
||
236 | 8 | $this->refId = $refId; |
|
237 | |||
238 | 8 | return $this; |
|
239 | } |
||
240 | |||
241 | /** |
||
242 | * Set reference entity name |
||
243 | * |
||
244 | * @param string $refEntityName |
||
245 | * |
||
246 | * @return NodeVersion |
||
247 | */ |
||
248 | 8 | protected function setRefEntityName($refEntityName) |
|
249 | { |
||
250 | 8 | $this->refEntityName = $refEntityName; |
|
251 | |||
252 | 8 | return $this; |
|
253 | } |
||
254 | |||
255 | /** |
||
256 | * Get reference entity name |
||
257 | * |
||
258 | * @return string |
||
259 | */ |
||
260 | 3 | public function getRefEntityName() |
|
261 | { |
||
262 | 3 | return $this->refEntityName; |
|
263 | } |
||
264 | |||
265 | 1 | public function getDefaultAdminType() |
|
266 | { |
||
267 | 1 | return null; |
|
268 | } |
||
269 | |||
270 | /** |
||
271 | * @return NodeVersion |
||
272 | */ |
||
273 | 8 | public function setRef(HasNodeInterface $entity) |
|
274 | { |
||
275 | 8 | $this->setRefId($entity->getId()); |
|
276 | 8 | $this->setRefEntityName(ClassLookup::getClass($entity)); |
|
277 | |||
278 | 8 | return $this; |
|
279 | } |
||
280 | |||
281 | /** |
||
282 | * @return HasNodeInterface |
||
0 ignored issues
–
show
|
|||
283 | */ |
||
284 | 2 | public function getRef(EntityManager $em) |
|
285 | { |
||
286 | 2 | return $em->getRepository($this->getRefEntityName())->find($this->getRefId()); |
|
287 | } |
||
288 | |||
289 | /** |
||
290 | * @param NodeVersion $origin |
||
291 | * |
||
292 | * @return NodeVersion |
||
293 | */ |
||
294 | 2 | public function setOrigin($origin) |
|
295 | { |
||
296 | 2 | $this->origin = $origin; |
|
297 | |||
298 | 2 | return $this; |
|
299 | } |
||
300 | |||
301 | /** |
||
302 | * @return NodeVersion |
||
303 | */ |
||
304 | 2 | public function getOrigin() |
|
305 | { |
||
306 | 2 | return $this->origin; |
|
307 | } |
||
308 | } |
||
309 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.