Completed
Push — master ( 48cc3d...5640fa )
by Craig
12:32 queued 05:19
created

AbstractRouteEntity::getCondition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Routes.
4
 *
5
 * @copyright Zikula contributors (Zikula)
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 * @author Zikula contributors <[email protected]>.
8
 * @link http://www.zikula.org
9
 * @link http://zikula.org
10
 * @version Generated by ModuleStudio 0.7.4 (http://modulestudio.de).
11
 */
12
13
namespace Zikula\RoutesModule\Entity\Base;
14
15
use Doctrine\ORM\Mapping as ORM;
16
use Gedmo\Mapping\Annotation as Gedmo;
17
use Symfony\Component\Validator\Constraints as Assert;
18
use Zikula\RoutesModule\Traits\StandardFieldsTrait;
19
use Zikula\RoutesModule\Validator\Constraints as RoutesAssert;
20
use Zikula\Core\Doctrine\EntityAccess;
21
22
/**
23
 * Entity class that defines the entity structure and behaviours.
24
 *
25
 * This is the base entity class for route entities.
26
 * The following annotation marks it as a mapped superclass so subclasses
27
 * inherit orm properties.
28
 *
29
 * @ORM\MappedSuperclass
30
 *
31
 * @abstract
32
 */
33
abstract class AbstractRouteEntity extends EntityAccess
34
{
35
    /**
36
     * Hook standard fields behaviour embedding createdBy, updatedBy, createdDate, updatedDate fields.
37
     */
38
    use StandardFieldsTrait;
39
40
    /**
41
     * @var string The tablename this object maps to
42
     */
43
    protected $_objectType = 'route';
44
    
45
    /**
46
     * @ORM\Id
47
     * @ORM\GeneratedValue(strategy="AUTO")
48
     * @ORM\Column(type="integer", unique=true)
49
     * @Assert\Type(type="integer")
50
     * @Assert\NotNull()
51
     * @Assert\LessThan(value=1000000000)
52
     * @var integer $id
53
     */
54
    protected $id = 0;
55
    
56
    /**
57
     * the current workflow state
58
     * @ORM\Column(length=20)
59
     * @Assert\NotBlank()
60
     * @RoutesAssert\ListEntry(entityName="route", propertyName="workflowState", multiple=false)
61
     * @var string $workflowState
62
     */
63
    protected $workflowState = 'initial';
64
    
65
    /**
66
     * @ORM\Column(length=255)
67
     * @Assert\NotBlank()
68
     * @RoutesAssert\ListEntry(entityName="route", propertyName="routeType", multiple=false)
69
     * @var string $routeType
70
     */
71
    protected $routeType = 'additional';
72
    
73
    /**
74
     * @ORM\Column(length=255, nullable=true)
75
     * @Assert\Length(min="0", max="255")
76
     * @var string $replacedRouteName
77
     */
78
    protected $replacedRouteName = '';
79
    
80
    /**
81
     * @ORM\Column(length=255)
82
     * @Assert\NotBlank()
83
     * @Assert\Length(min="0", max="255")
84
     * @var string $bundle
85
     */
86
    protected $bundle = '';
87
    
88
    /**
89
     * @ORM\Column(length=255)
90
     * @Assert\NotBlank()
91
     * @Assert\Length(min="0", max="255")
92
     * @var string $controller
93
     */
94
    protected $controller = '';
95
    
96
    /**
97
     * @ORM\Column(name="route_action", length=255)
98
     * @Assert\NotBlank()
99
     * @Assert\Length(min="0", max="255")
100
     * @var string $action
101
     */
102
    protected $action = '';
103
    
104
    /**
105
     * @ORM\Column(name="route_path", length=255)
106
     * @Assert\NotBlank()
107
     * @Assert\Length(min="0", max="255")
108
     * @var string $path
109
     */
110
    protected $path = '';
111
    
112
    /**
113
     * @ORM\Column(length=255, nullable=true)
114
     * @Assert\Length(min="0", max="255")
115
     * @var string $host
116
     */
117
    protected $host = '';
118
    
119
    /**
120
     * @ORM\Column(length=255)
121
     * @Assert\NotBlank()
122
     * @RoutesAssert\ListEntry(entityName="route", propertyName="schemes", multiple=true)
123
     * @var string $schemes
124
     */
125
    protected $schemes = 'http';
126
    
127
    /**
128
     * @ORM\Column(length=255)
129
     * @Assert\NotBlank()
130
     * @RoutesAssert\ListEntry(entityName="route", propertyName="methods", multiple=true)
131
     * @var string $methods
132
     */
133
    protected $methods = 'GET';
134
    
135
    /**
136
     * @ORM\Column(type="boolean")
137
     * @Assert\IsTrue(message="This option is mandatory.")
138
     * @Assert\Type(type="bool")
139
     * @var boolean $prependBundlePrefix
140
     */
141
    protected $prependBundlePrefix = true;
142
    
143
    /**
144
     * @ORM\Column(type="boolean")
145
     * @Assert\IsTrue(message="This option is mandatory.")
146
     * @Assert\Type(type="bool")
147
     * @var boolean $translatable
148
     */
149
    protected $translatable = true;
150
    
151
    /**
152
     * @ORM\Column(length=255, nullable=true)
153
     * @Assert\Length(min="0", max="255")
154
     * @var string $translationPrefix
155
     */
156
    protected $translationPrefix = '';
157
    
158
    /**
159
     * @ORM\Column(name="route_defaults", type="array")
160
     * @Assert\NotBlank()
161
     * @Assert\Type(type="array")
162
     * @var array $defaults
163
     */
164
    protected $defaults = [];
165
    
166
    /**
167
     * @ORM\Column(type="array")
168
     * @Assert\NotNull()
169
     * @Assert\Type(type="array")
170
     * @var array $requirements
171
     */
172
    protected $requirements = [];
173
    
174
    /**
175
     * @ORM\Column(name="route_condition", length=255, nullable=true)
176
     * @Assert\Length(min="0", max="255")
177
     * @var string $condition
178
     */
179
    protected $condition = '';
180
    
181
    /**
182
     * @ORM\Column(length=255, nullable=true)
183
     * @Assert\Length(min="0", max="255")
184
     * @var string $description
185
     */
186
    protected $description = '';
187
    
188
    /**
189
     * @Gedmo\SortablePosition
190
     * @ORM\Column(type="integer")
191
     * @Assert\Type(type="integer")
192
     * @Assert\NotNull()
193
     * @Assert\LessThan(value=100000000000)
194
     * @var integer $sort
195
     */
196
    protected $sort = 0;
197
    
198
    /**
199
     * @Gedmo\SortableGroup
200
     * @ORM\Column(name="sort_group", length=255)
201
     * @Assert\NotNull()
202
     * @Assert\Length(min="0", max="255")
203
     * @var string $group
204
     */
205
    protected $group = '';
206
    
207
    
208
    
209
    /**
210
     * RouteEntity constructor.
211
     *
212
     * Will not be called by Doctrine and can therefore be used
213
     * for own implementation purposes. It is also possible to add
214
     * arbitrary arguments as with every other class method.
215
     *
216
     * @param TODO
217
     */
218
    public function __construct()
219
    {
220
    }
221
    
222
    /**
223
     * Returns the _object type.
224
     *
225
     * @return string
226
     */
227
    public function get_objectType()
228
    {
229
        return $this->_objectType;
230
    }
231
    
232
    /**
233
     * Sets the _object type.
234
     *
235
     * @param string $_objectType
236
     *
237
     * @return void
238
     */
239
    public function set_objectType($_objectType)
240
    {
241
        $this->_objectType = $_objectType;
242
    }
243
    
244
    
245
    /**
246
     * Returns the id.
247
     *
248
     * @return integer
249
     */
250
    public function getId()
251
    {
252
        return $this->id;
253
    }
254
    
255
    /**
256
     * Sets the id.
257
     *
258
     * @param integer $id
259
     *
260
     * @return void
261
     */
262
    public function setId($id)
263
    {
264
        $this->id = intval($id);
265
    }
266
    
267
    /**
268
     * Returns the workflow state.
269
     *
270
     * @return string
271
     */
272
    public function getWorkflowState()
273
    {
274
        return $this->workflowState;
275
    }
276
    
277
    /**
278
     * Sets the workflow state.
279
     *
280
     * @param string $workflowState
281
     *
282
     * @return void
283
     */
284
    public function setWorkflowState($workflowState)
285
    {
286
        $this->workflowState = isset($workflowState) ? $workflowState : '';
287
    }
288
    
289
    /**
290
     * Returns the route type.
291
     *
292
     * @return string
293
     */
294
    public function getRouteType()
295
    {
296
        return $this->routeType;
297
    }
298
    
299
    /**
300
     * Sets the route type.
301
     *
302
     * @param string $routeType
303
     *
304
     * @return void
305
     */
306
    public function setRouteType($routeType)
307
    {
308
        $this->routeType = isset($routeType) ? $routeType : '';
309
    }
310
    
311
    /**
312
     * Returns the replaced route name.
313
     *
314
     * @return string
315
     */
316
    public function getReplacedRouteName()
317
    {
318
        return $this->replacedRouteName;
319
    }
320
    
321
    /**
322
     * Sets the replaced route name.
323
     *
324
     * @param string $replacedRouteName
325
     *
326
     * @return void
327
     */
328
    public function setReplacedRouteName($replacedRouteName)
329
    {
330
        $this->replacedRouteName = $replacedRouteName;
331
    }
332
    
333
    /**
334
     * Returns the bundle.
335
     *
336
     * @return string
337
     */
338
    public function getBundle()
339
    {
340
        return $this->bundle;
341
    }
342
    
343
    /**
344
     * Sets the bundle.
345
     *
346
     * @param string $bundle
347
     *
348
     * @return void
349
     */
350
    public function setBundle($bundle)
351
    {
352
        $this->bundle = isset($bundle) ? $bundle : '';
353
    }
354
    
355
    /**
356
     * Returns the controller.
357
     *
358
     * @return string
359
     */
360
    public function getController()
361
    {
362
        return $this->controller;
363
    }
364
    
365
    /**
366
     * Sets the controller.
367
     *
368
     * @param string $controller
369
     *
370
     * @return void
371
     */
372
    public function setController($controller)
373
    {
374
        $this->controller = isset($controller) ? $controller : '';
375
    }
376
    
377
    /**
378
     * Returns the action.
379
     *
380
     * @return string
381
     */
382
    public function getAction()
383
    {
384
        return $this->action;
385
    }
386
    
387
    /**
388
     * Sets the action.
389
     *
390
     * @param string $action
391
     *
392
     * @return void
393
     */
394
    public function setAction($action)
395
    {
396
        $this->action = isset($action) ? $action : '';
397
    }
398
    
399
    /**
400
     * Returns the path.
401
     *
402
     * @return string
403
     */
404
    public function getPath()
405
    {
406
        return $this->path;
407
    }
408
    
409
    /**
410
     * Sets the path.
411
     *
412
     * @param string $path
413
     *
414
     * @return void
415
     */
416
    public function setPath($path)
417
    {
418
        $this->path = isset($path) ? $path : '';
419
    }
420
    
421
    /**
422
     * Returns the host.
423
     *
424
     * @return string
425
     */
426
    public function getHost()
427
    {
428
        return $this->host;
429
    }
430
    
431
    /**
432
     * Sets the host.
433
     *
434
     * @param string $host
435
     *
436
     * @return void
437
     */
438
    public function setHost($host)
439
    {
440
        $this->host = $host;
441
    }
442
    
443
    /**
444
     * Returns the schemes.
445
     *
446
     * @return string
447
     */
448
    public function getSchemes()
449
    {
450
        return $this->schemes;
451
    }
452
    
453
    /**
454
     * Sets the schemes.
455
     *
456
     * @param string $schemes
457
     *
458
     * @return void
459
     */
460
    public function setSchemes($schemes)
461
    {
462
        $this->schemes = isset($schemes) ? $schemes : '';
463
    }
464
    
465
    /**
466
     * Returns the methods.
467
     *
468
     * @return string
469
     */
470
    public function getMethods()
471
    {
472
        return $this->methods;
473
    }
474
    
475
    /**
476
     * Sets the methods.
477
     *
478
     * @param string $methods
479
     *
480
     * @return void
481
     */
482
    public function setMethods($methods)
483
    {
484
        $this->methods = isset($methods) ? $methods : '';
485
    }
486
    
487
    /**
488
     * Returns the prepend bundle prefix.
489
     *
490
     * @return boolean
491
     */
492
    public function getPrependBundlePrefix()
493
    {
494
        return $this->prependBundlePrefix;
495
    }
496
    
497
    /**
498
     * Sets the prepend bundle prefix.
499
     *
500
     * @param boolean $prependBundlePrefix
501
     *
502
     * @return void
503
     */
504
    public function setPrependBundlePrefix($prependBundlePrefix)
505
    {
506
        if ($prependBundlePrefix !== $this->prependBundlePrefix) {
507
            $this->prependBundlePrefix = (bool)$prependBundlePrefix;
508
        }
509
    }
510
    
511
    /**
512
     * Returns the translatable.
513
     *
514
     * @return boolean
515
     */
516
    public function getTranslatable()
517
    {
518
        return $this->translatable;
519
    }
520
    
521
    /**
522
     * Sets the translatable.
523
     *
524
     * @param boolean $translatable
525
     *
526
     * @return void
527
     */
528
    public function setTranslatable($translatable)
529
    {
530
        if ($translatable !== $this->translatable) {
531
            $this->translatable = (bool)$translatable;
532
        }
533
    }
534
    
535
    /**
536
     * Returns the translation prefix.
537
     *
538
     * @return string
539
     */
540
    public function getTranslationPrefix()
541
    {
542
        return $this->translationPrefix;
543
    }
544
    
545
    /**
546
     * Sets the translation prefix.
547
     *
548
     * @param string $translationPrefix
549
     *
550
     * @return void
551
     */
552
    public function setTranslationPrefix($translationPrefix)
553
    {
554
        $this->translationPrefix = $translationPrefix;
555
    }
556
    
557
    /**
558
     * Returns the defaults.
559
     *
560
     * @return array
561
     */
562
    public function getDefaults()
563
    {
564
        return $this->defaults;
565
    }
566
    
567
    /**
568
     * Sets the defaults.
569
     *
570
     * @param array $defaults
571
     *
572
     * @return void
573
     */
574
    public function setDefaults($defaults)
575
    {
576
        $this->defaults = isset($defaults) ? $defaults : '';
0 ignored issues
show
Documentation Bug introduced by
It seems like isset($defaults) ? $defaults : '' can also be of type string. However, the property $defaults is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
577
    }
578
    
579
    /**
580
     * Returns the requirements.
581
     *
582
     * @return array
583
     */
584
    public function getRequirements()
585
    {
586
        return $this->requirements;
587
    }
588
    
589
    /**
590
     * Sets the requirements.
591
     *
592
     * @param array $requirements
593
     *
594
     * @return void
595
     */
596
    public function setRequirements($requirements)
597
    {
598
        $this->requirements = isset($requirements) ? $requirements : '';
0 ignored issues
show
Documentation Bug introduced by
It seems like isset($requirements) ? $requirements : '' can also be of type string. However, the property $requirements is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
599
    }
600
    
601
    /**
602
     * Returns the condition.
603
     *
604
     * @return string
605
     */
606
    public function getCondition()
607
    {
608
        return $this->condition;
609
    }
610
    
611
    /**
612
     * Sets the condition.
613
     *
614
     * @param string $condition
615
     *
616
     * @return void
617
     */
618
    public function setCondition($condition)
619
    {
620
        $this->condition = $condition;
621
    }
622
    
623
    /**
624
     * Returns the description.
625
     *
626
     * @return string
627
     */
628
    public function getDescription()
629
    {
630
        return $this->description;
631
    }
632
    
633
    /**
634
     * Sets the description.
635
     *
636
     * @param string $description
637
     *
638
     * @return void
639
     */
640
    public function setDescription($description)
641
    {
642
        $this->description = $description;
643
    }
644
    
645
    /**
646
     * Returns the sort.
647
     *
648
     * @return integer
649
     */
650
    public function getSort()
651
    {
652
        return $this->sort;
653
    }
654
    
655
    /**
656
     * Sets the sort.
657
     *
658
     * @param integer $sort
659
     *
660
     * @return void
661
     */
662
    public function setSort($sort)
663
    {
664
        $this->sort = intval($sort);
665
    }
666
    
667
    /**
668
     * Returns the group.
669
     *
670
     * @return string
671
     */
672
    public function getGroup()
673
    {
674
        return $this->group;
675
    }
676
    
677
    /**
678
     * Sets the group.
679
     *
680
     * @param string $group
681
     *
682
     * @return void
683
     */
684
    public function setGroup($group)
685
    {
686
        $this->group = isset($group) ? $group : '';
687
    }
688
    
689
    
690
    
691
    /**
692
     * Returns the formatted title conforming to the display pattern
693
     * specified for this entity.
694
     *
695
     * @return string The display title
696
     */
697
    public function getTitleFromDisplayPattern()
698
    {
699
        $formattedTitle = ''
700
                . $this->getPath()
701
                . ' ('
702
                . $this->getSort()
703
                . ')';
704
    
705
        return $formattedTitle;
706
    }
707
    
708
    /**
709
     * Return entity data in JSON format.
710
     *
711
     * @return string JSON-encoded data
712
     */
713
    public function toJson()
714
    {
715
        return json_encode($this->toArray());
716
    }
717
    
718
    /**
719
     * Creates url arguments array for easy creation of display urls.
720
     *
721
     * @return array The resulting arguments list
722
     */
723
    public function createUrlArgs()
724
    {
725
        $args = [];
726
    
727
        $args['id'] = $this['id'];
728
    
729
        if (property_exists($this, 'slug')) {
730
            $args['slug'] = $this['slug'];
731
        }
732
    
733
        return $args;
734
    }
735
    
736
    /**
737
     * Create concatenated identifier string (for composite keys).
738
     *
739
     * @return String concatenated identifiers
740
     */
741
    public function createCompositeIdentifier()
742
    {
743
        $itemId = $this['id'];
744
    
745
        return $itemId;
746
    }
747
    
748
    /**
749
     * Determines whether this entity supports hook subscribers or not.
750
     *
751
     * @return boolean
752
     */
753
    public function supportsHookSubscribers()
754
    {
755
        return false;
756
    }
757
    
758
    /**
759
     * Returns an array of all related objects that need to be persisted after clone.
760
     * 
761
     * @param array $objects The objects are added to this array. Default: []
762
     * 
763
     * @return array of entity objects
764
     */
765
    public function getRelatedObjectsToPersist(&$objects = []) 
0 ignored issues
show
Unused Code introduced by
The parameter $objects is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
766
    {
767
        return [];
768
    }
769
    
770
    /**
771
     * ToString interceptor implementation.
772
     * This method is useful for debugging purposes.
773
     *
774
     * @return string The output string for this entity
775
     */
776
    public function __toString()
777
    {
778
        return 'Route ' . $this->createCompositeIdentifier() . ': ' . $this->getTitleFromDisplayPattern();
779
    }
780
    
781
    /**
782
     * Clone interceptor implementation.
783
     * This method is for example called by the reuse functionality.
784
     * Performs a quite simple shallow copy.
785
     *
786
     * See also:
787
     * (1) http://docs.doctrine-project.org/en/latest/cookbook/implementing-wakeup-or-clone.html
788
     * (2) http://www.php.net/manual/en/language.oop5.cloning.php
789
     * (3) http://stackoverflow.com/questions/185934/how-do-i-create-a-copy-of-an-object-in-php
790
     */
791
    public function __clone()
792
    {
793
        // if the entity has no identity do nothing, do NOT throw an exception
794
        if (!($this->id)) {
795
            return;
796
        }
797
    
798
        // otherwise proceed
799
    
800
        // unset identifiers
801
        $this->setId(0);
802
    
803
        $this->setCreatedBy(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Zikula\UsersModule\Entity\UserEntity>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
804
        $this->setCreatedDate(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<DateTime>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
805
        $this->setUpdatedBy(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Zikula\UsersModule\Entity\UserEntity>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
806
        $this->setUpdatedDate(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<DateTime>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
807
    
808
    }
809
}
810