Completed
Pull Request — master (#374)
by Leny
06:07
created

Link::setLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 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
10
/**
11
 * Victoire Link.
12
 *
13
 * @ORM\Entity
14
 * @ORM\Table("vic_link")
15
 */
16
class Link
17
{
18
    const TYPE_NONE = 'none';
19
    const TYPE_VIEW_REFERENCE = 'viewReference';
20
    const TYPE_ROUTE = 'route';
21
    const TYPE_URL = 'url';
22
    const TYPE_WIDGET = 'attachedWidget';
23
24
    use \Gedmo\Timestampable\Traits\TimestampableEntity;
25
26
    /**
27
     * @var int
28
     *
29
     * @ORM\Column(name="id", type="integer")
30
     * @ORM\Id
31
     * @ORM\GeneratedValue(strategy="AUTO")
32
     */
33
    protected $id;
34
35
    /**
36
     * @var string
37
     *
38
     * @ORM\Column(name="url", type="string", length=255, nullable=true)
39
     */
40
    protected $url;
41
42
    /**
43
     * @var string
44
     *
45
     * @ORM\Column(name="locale", type="string", length=255, nullable=true)
46
     */
47
    protected $locale = null;
48
49
    /**
50
     * @var string
51
     *
52
     * @ORM\Column(name="target", type="string", length=10, nullable=true)
53
     */
54
    protected $target = '_parent';
55
56
    /**
57
     * @ORM\Column(name="view_reference", type="string", length=255, nullable=true)
58
     */
59
    protected $viewReference;
60
61
    /**
62
     * @ORM\ManyToOne(targetEntity="Victoire\Bundle\WidgetBundle\Entity\Widget")
63
     * @ORM\JoinColumn(name="attached_widget_id", referencedColumnName="id", onDelete="cascade", nullable=true)
64
     */
65
    protected $attachedWidget;
66
67
    /**
68
     * @var string
69
     *
70
     * @ORM\Column(name="route", type="string", length=55, nullable=true)
71
     */
72
    protected $route;
73
74
    /**
75
     * @var string
76
     *
77
     * @ORM\Column(name="route_parameters", type="array", nullable=true)
78
     */
79
    protected $routeParameters = [];
80
81
    /**
82
     * @var string
83
     *
84
     * @ORM\Column(name="link_type", type="string", length=255, nullable=true)
85
     */
86
    protected $linkType = self::TYPE_NONE;
87
88
    /**
89
     * @var string
90
     *
91
     * @ORM\Column(name="analytics_track_code", type="text", nullable=true)
92
     */
93
    protected $analyticsTrackCode;
94
95
    protected $parameters;
96
    protected $viewReferencePage;
97
98
    /**
99
     * Get id.
100
     *
101
     * @return int
102
     */
103
    public function getId()
104
    {
105
        return $this->id;
106
    }
107
108
    /**
109
     * Set id.
110
     *
111
     * @param string $id
112
     *
113
     * @return Link
114
     */
115
    public function setId($id)
116
    {
117
        $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...
118
119
        return $this;
120
    }
121
122
    public function getParameters()
123
    {
124
        return $this->parameters = [
125
            'analyticsTrackCode' => $this->analyticsTrackCode,
126
            'attachedWidget'     => $this->attachedWidget,
127
            'linkType'           => $this->linkType,
128
            'locale'             => $this->locale,
129
            'route'              => $this->route,
130
            'routeParameters'    => $this->routeParameters,
131
            'target'             => $this->target,
132
            'url'                => $this->url,
133
            'viewReference'      => $this->viewReference,
134
            'viewReferencePage'  => $this->viewReferencePage,
135
        ];
136
    }
137
138
    /**
139
     * Set url.
140
     *
141
     * @param string $url
142
     *
143
     * @return Link
144
     */
145
    public function setUrl($url)
146
    {
147
        $this->url = $url;
148
149
        return $this;
150
    }
151
152
    /**
153
     * Get url.
154
     *
155
     * @return string
156
     */
157
    public function getUrl()
158
    {
159
        return $this->url;
160
    }
161
162
    /**
163
     * Set target.
164
     *
165
     * @param string $target
166
     *
167
     * @return Link
168
     */
169
    public function setTarget($target)
170
    {
171
        $this->target = $target;
172
173
        return $this;
174
    }
175
176
    /**
177
     * Get target.
178
     *
179
     * @return string
180
     */
181
    public function getTarget()
182
    {
183
        return $this->target;
184
    }
185
186
    /**
187
     * Set route.
188
     *
189
     * @param string $route
190
     *
191
     * @return Link
192
     */
193
    public function setRoute($route)
194
    {
195
        $this->route = $route;
196
197
        return $this;
198
    }
199
200
    /**
201
     * Get route.
202
     *
203
     * @return string
204
     */
205
    public function getRoute()
206
    {
207
        return $this->route;
208
    }
209
210
    /**
211
     * Set routeParameters.
212
     *
213
     * @param array $routeParameters
214
     *
215
     * @return Link
216
     */
217
    public function setRouteParameters($routeParameters)
218
    {
219
        $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...
220
221
        return $this;
222
    }
223
224
    /**
225
     * Get routeParameters.
226
     *
227
     * @return string
228
     */
229
    public function getRouteParameters()
230
    {
231
        return $this->routeParameters;
232
    }
233
234
    /**
235
     * Get viewReference.
236
     *
237
     * @return string
238
     */
239
    public function getViewReference()
240
    {
241
        return $this->viewReference;
242
    }
243
244
    /**
245
     * Set viewReference.
246
     *
247
     * @param string $viewReference
248
     *
249
     * @return Link
250
     */
251
    public function setViewReference($viewReference)
252
    {
253
        $this->viewReference = $viewReference;
254
255
        return $this;
256
    }
257
258
    /**
259
     * Set linkType.
260
     *
261
     * @param string $linkType
262
     *
263
     * @return Link
264
     */
265
    public function setLinkType($linkType)
266
    {
267
        $this->linkType = $linkType;
268
269
        return $this;
270
    }
271
272
    /**
273
     * Get linkType.
274
     *
275
     * @return string
276
     */
277
    public function getLinkType()
278
    {
279
        return $this->linkType;
280
    }
281
282
    /**
283
     * Get attachedWidget.
284
     *
285
     * @return string
286
     */
287
    public function getAttachedWidget()
288
    {
289
        return $this->attachedWidget;
290
    }
291
292
    /**
293
     * Set attachedWidget.
294
     *
295
     * @param string $attachedWidget
296
     *
297
     * @return Link
298
     */
299
    public function setAttachedWidget($attachedWidget)
300
    {
301
        $this->attachedWidget = $attachedWidget;
302
303
        return $this;
304
    }
305
306
    public static function loadValidatorMetadata(ClassMetadata $metadata)
307
    {
308
        $metadata->addConstraint(new Assert\Callback('checkLink'));
309
    }
310
311
    /**
312
     * undocumented function.
313
     *
314
     * @param ExecutionContextInterface $context
315
     *
316
     * @author
317
     */
318
    public function checkLink(ExecutionContextInterface $context)
319
    {
320
        $violation = false;
321
        // check if the name is actually a fake name
322
        switch ($this->getLinkType()) {
323
            case self::TYPE_VIEW_REFERENCE:
324
            $violation = $this->getViewReference() == null;
325
                break;
326
            case self::TYPE_ROUTE:
327
            $violation = $this->getRoute() == null;
328
                break;
329
            case self::TYPE_URL:
330
            $violation = $this->getUrl() == null;
331
                break;
332
            case self::TYPE_WIDGET:
333
            $violation = $this->getAttachedWidget() == null;
334
                break;
335
            default:
336
                break;
337
        }
338
339
        if ($violation) {
340
            $context->buildViolation('validator.link.error.message.'.$this->getLinkType().'Missing')->addViolation();
341
        }
342
    }
343
344
    /**
345
     * Get analyticsTrackCode.
346
     *
347
     * @return string
348
     */
349
    public function getAnalyticsTrackCode()
350
    {
351
        return $this->analyticsTrackCode;
352
    }
353
354
    /**
355
     * Set analyticsTrackCode.
356
     *
357
     * @param string $analyticsTrackCode
358
     *
359
     * @return Link
360
     */
361
    public function setAnalyticsTrackCode($analyticsTrackCode)
362
    {
363
        $this->analyticsTrackCode = $analyticsTrackCode;
364
365
        return $this;
366
    }
367
368
    /**
369
     * Get viewReferencePage.
370
     *
371
     * @return mixed
372
     */
373
    public function getViewReferencePage()
374
    {
375
        return $this->viewReferencePage;
376
    }
377
378
    /**
379
     * Set viewReferencePage.
380
     *
381
     * @param mixed $viewReferencePage
382
     *
383
     * @return Link
384
     */
385
    public function setViewReferencePage($viewReferencePage)
386
    {
387
        $this->viewReferencePage = $viewReferencePage;
388
389
        return $this;
390
    }
391
392
    /**
393
     * @return string
394
     */
395
    public function getLocale()
396
    {
397
        return $this->locale;
398
    }
399
400
    /**
401
     * @param string $locale
402
     *
403
     * @return Link
404
     */
405
    public function setLocale($locale)
406
    {
407
        $this->locale = $locale;
408
409
        return $this;
410
    }
411
}
412