Completed
Pull Request — master (#374)
by Leny
28:15 queued 21:44
created

Link   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 396
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 30
lcom 1
cbo 5
dl 0
loc 396
rs 10
c 4
b 1
f 0

25 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A setId() 0 6 1
A getParameters() 0 15 1
A setUrl() 0 6 1
A getUrl() 0 4 1
A setTarget() 0 6 1
A getTarget() 0 4 1
A setRoute() 0 6 1
A getRoute() 0 4 1
A setRouteParameters() 0 6 1
A getRouteParameters() 0 4 1
A getViewReference() 0 4 1
A setViewReference() 0 6 1
A setLinkType() 0 6 1
A getLinkType() 0 4 1
A getAttachedWidget() 0 4 1
A setAttachedWidget() 0 6 1
A loadValidatorMetadata() 0 4 1
B checkLink() 0 25 6
A getAnalyticsTrackCode() 0 4 1
A setAnalyticsTrackCode() 0 6 1
A getViewReferencePage() 0 4 1
A setViewReferencePage() 0 6 1
A getLocale() 0 4 1
A setLocale() 0 6 1
1
<?php
2
3
namespace Victoire\Bundle\CoreBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Symfony\Component\Validator\Constraints as Assert;
7
use Symfony\Component\Validator\Context\ExecutionContextInterface;
8
use Symfony\Component\Validator\Mapping\ClassMetadata;
9
use Victoire\Bundle\PageBundle\Entity\Page;
10
11
/**
12
 * Victoire Link.
13
 *
14
 * @ORM\Entity
15
 * @ORM\Table("vic_link")
16
 */
17
class Link
18
{
19
    const TYPE_NONE = 'none';
20
    const TYPE_VIEW_REFERENCE = 'viewReference';
21
    const TYPE_ROUTE = 'route';
22
    const TYPE_URL = 'url';
23
    const TYPE_WIDGET = 'attachedWidget';
24
25
    use \Gedmo\Timestampable\Traits\TimestampableEntity;
26
27
    /**
28
     * @var int
29
     *
30
     * @ORM\Column(name="id", type="integer")
31
     * @ORM\Id
32
     * @ORM\GeneratedValue(strategy="AUTO")
33
     */
34
    protected $id;
35
36
    /**
37
     * @var string
38
     *
39
     * @ORM\Column(name="url", type="string", length=255, nullable=true)
40
     */
41
    protected $url;
42
43
    /**
44
     * @var string
45
     *
46
     * @ORM\Column(name="locale", type="string", length=255, nullable=true)
47
     */
48
    protected $locale = null;
49
50
    /**
51
     * @var string
52
     *
53
     * @ORM\Column(name="target", type="string", length=10, nullable=true)
54
     */
55
    protected $target = '_parent';
56
57
    /**
58
     * @ORM\Column(name="view_reference", type="string", length=255, nullable=true)
59
     */
60
    protected $viewReference;
61
62
    /**
63
     * @ORM\ManyToOne(targetEntity="Victoire\Bundle\WidgetBundle\Entity\Widget")
64
     * @ORM\JoinColumn(name="attached_widget_id", referencedColumnName="id", onDelete="cascade", nullable=true)
65
     */
66
    protected $attachedWidget;
67
68
    /**
69
     * @var string
70
     *
71
     * @ORM\Column(name="route", type="string", length=55, nullable=true)
72
     */
73
    protected $route;
74
75
    /**
76
     * @var string
77
     *
78
     * @ORM\Column(name="route_parameters", type="array", nullable=true)
79
     */
80
    protected $routeParameters = [];
81
82
    /**
83
     * @var string
84
     *
85
     * @ORM\Column(name="link_type", type="string", length=255, nullable=true)
86
     */
87
    protected $linkType = self::TYPE_NONE;
88
89
    /**
90
     * @var string
91
     *
92
     * @ORM\Column(name="analytics_track_code", type="text", nullable=true)
93
     */
94
    protected $analyticsTrackCode;
95
96
    protected $parameters;
97
    protected $viewReferencePage;
98
99
    /**
100
     * Get id.
101
     *
102
     * @return int
103
     */
104
    public function getId()
105
    {
106
        return $this->id;
107
    }
108
109
    /**
110
     * Set id.
111
     *
112
     * @param string $id
113
     *
114
     * @return Link
115
     */
116
    public function setId($id)
117
    {
118
        $this->id = $id;
0 ignored issues
show
Documentation Bug introduced by
The property $id was declared of type integer, but $id is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
119
120
        return $this;
121
    }
122
123
    public function getParameters()
124
    {
125
        return $this->parameters = [
126
            'analyticsTrackCode' => $this->analyticsTrackCode,
127
            'attachedWidget'     => $this->attachedWidget,
128
            'linkType'           => $this->linkType,
129
            'locale'             => $this->locale,
130
            'route'              => $this->route,
131
            'routeParameters'    => $this->routeParameters,
132
            'target'             => $this->target,
133
            'url'                => $this->url,
134
            'viewReference'      => $this->viewReference,
135
            'viewReferencePage'  => $this->viewReferencePage,
136
        ];
137
    }
138
139
    /**
140
     * Set url.
141
     *
142
     * @param string $url
143
     *
144
     * @return Link
145
     */
146
    public function setUrl($url)
147
    {
148
        $this->url = $url;
149
150
        return $this;
151
    }
152
153
    /**
154
     * Get url.
155
     *
156
     * @return string
157
     */
158
    public function getUrl()
159
    {
160
        return $this->url;
161
    }
162
163
    /**
164
     * Set target.
165
     *
166
     * @param string $target
167
     *
168
     * @return Link
169
     */
170
    public function setTarget($target)
171
    {
172
        $this->target = $target;
173
174
        return $this;
175
    }
176
177
    /**
178
     * Get target.
179
     *
180
     * @return string
181
     */
182
    public function getTarget()
183
    {
184
        return $this->target;
185
    }
186
187
    /**
188
     * Set route.
189
     *
190
     * @param string $route
191
     *
192
     * @return Link
193
     */
194
    public function setRoute($route)
195
    {
196
        $this->route = $route;
197
198
        return $this;
199
    }
200
201
    /**
202
     * Get route.
203
     *
204
     * @return string
205
     */
206
    public function getRoute()
207
    {
208
        return $this->route;
209
    }
210
211
    /**
212
     * Set routeParameters.
213
     *
214
     * @param array $routeParameters
215
     *
216
     * @return Link
217
     */
218
    public function setRouteParameters($routeParameters)
219
    {
220
        $this->routeParameters = $routeParameters;
0 ignored issues
show
Documentation Bug introduced by
It seems like $routeParameters of type array is incompatible with the declared type string of property $routeParameters.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
221
222
        return $this;
223
    }
224
225
    /**
226
     * Get routeParameters.
227
     *
228
     * @return string
229
     */
230
    public function getRouteParameters()
231
    {
232
        return $this->routeParameters;
233
    }
234
235
    /**
236
     * Get viewReference.
237
     *
238
     * @return string
239
     */
240
    public function getViewReference()
241
    {
242
        return $this->viewReference;
243
    }
244
245
    /**
246
     * Set viewReference.
247
     *
248
     * @param string $viewReference
249
     *
250
     * @return Link
251
     */
252
    public function setViewReference($viewReference)
253
    {
254
        $this->viewReference = $viewReference;
255
256
        return $this;
257
    }
258
259
    /**
260
     * Set linkType.
261
     *
262
     * @param string $linkType
263
     *
264
     * @return Link
265
     */
266
    public function setLinkType($linkType)
267
    {
268
        $this->linkType = $linkType;
269
270
        return $this;
271
    }
272
273
    /**
274
     * Get linkType.
275
     *
276
     * @return string
277
     */
278
    public function getLinkType()
279
    {
280
        return $this->linkType;
281
    }
282
283
    /**
284
     * Get attachedWidget.
285
     *
286
     * @return string
287
     */
288
    public function getAttachedWidget()
289
    {
290
        return $this->attachedWidget;
291
    }
292
293
    /**
294
     * Set attachedWidget.
295
     *
296
     * @param string $attachedWidget
297
     *
298
     * @return Link
299
     */
300
    public function setAttachedWidget($attachedWidget)
301
    {
302
        $this->attachedWidget = $attachedWidget;
303
304
        return $this;
305
    }
306
307
    public static function loadValidatorMetadata(ClassMetadata $metadata)
308
    {
309
        $metadata->addConstraint(new Assert\Callback('checkLink'));
310
    }
311
312
    /**
313
     * undocumented function.
314
     *
315
     * @param ExecutionContextInterface $context
316
     *
317
     * @author
318
     */
319
    public function checkLink(ExecutionContextInterface $context)
320
    {
321
        $violation = false;
322
        // check if the name is actually a fake name
323
        switch ($this->getLinkType()) {
324
            case self::TYPE_VIEW_REFERENCE:
325
            $violation = $this->getViewReference() == null;
326
                break;
327
            case self::TYPE_ROUTE:
328
            $violation = $this->getRoute() == null;
329
                break;
330
            case self::TYPE_URL:
331
            $violation = $this->getUrl() == null;
332
                break;
333
            case self::TYPE_WIDGET:
334
            $violation = $this->getAttachedWidget() == null;
335
                break;
336
            default:
337
                break;
338
        }
339
340
        if ($violation) {
341
            $context->buildViolation('validator.link.error.message.'.$this->getLinkType().'Missing')->addViolation();
342
        }
343
    }
344
345
    /**
346
     * Get analyticsTrackCode.
347
     *
348
     * @return string
349
     */
350
    public function getAnalyticsTrackCode()
351
    {
352
        return $this->analyticsTrackCode;
353
    }
354
355
    /**
356
     * Set analyticsTrackCode.
357
     *
358
     * @param string $analyticsTrackCode
359
     *
360
     * @return Link
361
     */
362
    public function setAnalyticsTrackCode($analyticsTrackCode)
363
    {
364
        $this->analyticsTrackCode = $analyticsTrackCode;
365
366
        return $this;
367
    }
368
369
    /**
370
     * Get viewReferencePage.
371
     *
372
     * @return mixed
373
     */
374
    public function getViewReferencePage()
375
    {
376
        return $this->viewReferencePage;
377
    }
378
379
    /**
380
     * Set viewReferencePage.
381
     *
382
     * @param mixed $viewReferencePage
383
     *
384
     * @return Link
385
     */
386
    public function setViewReferencePage($viewReferencePage)
387
    {
388
        $this->viewReferencePage = $viewReferencePage;
389
390
        return $this;
391
    }
392
393
    /**
394
     * @return string
395
     */
396
    public function getLocale()
397
    {
398
        return $this->locale;
399
    }
400
401
    /**
402
     * @param string $locale
403
     *
404
     * @return Link
405
     */
406
    public function setLocale($locale)
407
    {
408
        $this->locale = $locale;
409
410
        return $this;
411
    }
412
}
413