Completed
Push — master ( 2fb092...058edd )
by Craig
06:38
created

AbstractRouteEntity::get__WORKFLOW__()   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.1 (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 Symfony\Component\Validator\Context\ExecutionContextInterface;
19
use Zikula\RoutesModule\Traits\EntityWorkflowTrait;
20
use Zikula\RoutesModule\Traits\StandardFieldsTrait;
21
22
use RuntimeException;
23
use ServiceUtil;
24
use Zikula\Core\Doctrine\EntityAccess;
25
26
/**
27
 * Entity class that defines the entity structure and behaviours.
28
 *
29
 * This is the base entity class for route entities.
30
 * The following annotation marks it as a mapped superclass so subclasses
31
 * inherit orm properties.
32
 *
33
 * @ORM\MappedSuperclass
34
 *
35
 * @abstract
36
 */
37
abstract class AbstractRouteEntity extends EntityAccess
38
{
39
    /**
40
     * Hook entity workflow field and behaviour.
41
     */
42
    use EntityWorkflowTrait;
43
44
    /**
45
     * Hook standard fields behaviour embedding createdBy, updatedBy, createdDate, updatedDate fields.
46
     */
47
    use StandardFieldsTrait;
48
49
    /**
50
     * @var string The tablename this object maps to
51
     */
52
    protected $_objectType = 'route';
53
    
54
    /**
55
     * @Assert\Type(type="bool")
56
     * @var boolean Option to bypass validation if needed
57
     */
58
    protected $_bypassValidation = false;
59
    
60
    /**
61
     * @ORM\Id
62
     * @ORM\GeneratedValue(strategy="AUTO")
63
     * @ORM\Column(type="integer", unique=true)
64
     * @Assert\Type(type="integer")
65
     * @Assert\NotNull()
66
     * @Assert\LessThan(value=1000000000, message="Length of field value must not be higher than 9.")) {
67
     * @var integer $id
68
     */
69
    protected $id = 0;
70
    
71
    /**
72
     * the current workflow state
73
     * @ORM\Column(length=20)
74
     * @Assert\NotBlank()
75
     * @Assert\Choice(callback="getWorkflowStateAllowedValues", multiple=false)
76
     * @var string $workflowState
77
     */
78
    protected $workflowState = 'initial';
79
    
80
    /**
81
     * @ORM\Column(length=255)
82
     * @Assert\NotBlank()
83
     * @Assert\Choice(callback="getRouteTypeAllowedValues", multiple=false)
84
     * @var string $routeType
85
     */
86
    protected $routeType = 'additional';
87
    
88
    /**
89
     * @ORM\Column(length=255, nullable=true)
90
     * @Assert\Length(min="0", max="255")
91
     * @var string $replacedRouteName
92
     */
93
    protected $replacedRouteName = '';
94
    
95
    /**
96
     * @ORM\Column(length=255)
97
     * @Assert\NotBlank()
98
     * @Assert\Length(min="0", max="255")
99
     * @var string $bundle
100
     */
101
    protected $bundle = '';
102
    
103
    /**
104
     * @ORM\Column(length=255)
105
     * @Assert\NotBlank()
106
     * @Assert\Length(min="0", max="255")
107
     * @var string $controller
108
     */
109
    protected $controller = '';
110
    
111
    /**
112
     * @ORM\Column(name="route_action", length=255)
113
     * @Assert\NotBlank()
114
     * @Assert\Length(min="0", max="255")
115
     * @var string $action
116
     */
117
    protected $action = '';
118
    
119
    /**
120
     * @ORM\Column(name="route_path", length=255)
121
     * @Assert\NotBlank()
122
     * @Assert\Length(min="0", max="255")
123
     * @var string $path
124
     */
125
    protected $path = '';
126
    
127
    /**
128
     * @ORM\Column(length=255, nullable=true)
129
     * @Assert\Length(min="0", max="255")
130
     * @var string $host
131
     */
132
    protected $host = '';
133
    
134
    /**
135
     * @ORM\Column(length=255)
136
     * @Assert\NotBlank()
137
     * @var string $schemes
138
     */
139
    protected $schemes = 'http';
140
    
141
    /**
142
     * @ORM\Column(length=255)
143
     * @Assert\NotBlank()
144
     * @var string $methods
145
     */
146
    protected $methods = 'GET';
147
    
148
    /**
149
     * @ORM\Column(type="boolean")
150
     * @Assert\IsTrue(message="This option is mandatory.")
151
     * @Assert\Type(type="bool")
152
     * @var boolean $prependBundlePrefix
153
     */
154
    protected $prependBundlePrefix = true;
155
    
156
    /**
157
     * @ORM\Column(type="boolean")
158
     * @Assert\IsTrue(message="This option is mandatory.")
159
     * @Assert\Type(type="bool")
160
     * @var boolean $translatable
161
     */
162
    protected $translatable = true;
163
    
164
    /**
165
     * @ORM\Column(length=255, nullable=true)
166
     * @Assert\Length(min="0", max="255")
167
     * @var string $translationPrefix
168
     */
169
    protected $translationPrefix = '';
170
    
171
    /**
172
     * @ORM\Column(name="route_defaults", type="array")
173
     * @Assert\NotBlank()
174
     * @Assert\Type(type="array")
175
     * @var array $defaults
176
     */
177
    protected $defaults = [];
178
    
179
    /**
180
     * @ORM\Column(type="array")
181
     * @Assert\NotNull()
182
     * @Assert\Type(type="array")
183
     * @var array $requirements
184
     */
185
    protected $requirements = [];
186
    
187
    /**
188
     * @ORM\Column(name="route_condition", length=255, nullable=true)
189
     * @Assert\Length(min="0", max="255")
190
     * @var string $condition
191
     */
192
    protected $condition = '';
193
    
194
    /**
195
     * @ORM\Column(length=255, nullable=true)
196
     * @Assert\Length(min="0", max="255")
197
     * @var string $description
198
     */
199
    protected $description = '';
200
    
201
    /**
202
     * @Gedmo\SortablePosition
203
     * @ORM\Column(type="integer")
204
     * @Assert\Type(type="integer")
205
     * @Assert\NotNull()
206
     * @Assert\LessThan(value=2147483647, message="Length of field value must not be higher than 11.")) {
207
     * @var integer $sort
208
     */
209
    protected $sort = 0;
210
    
211
    /**
212
     * @Gedmo\SortableGroup
213
     * @ORM\Column(name="sort_group", length=255)
214
     * @Assert\NotNull()
215
     * @Assert\Length(min="0", max="255")
216
     * @var string $group
217
     */
218
    protected $group = '';
219
    
220
    
221
    
222
    /**
223
     * RouteEntity constructor.
224
     *
225
     * Will not be called by Doctrine and can therefore be used
226
     * for own implementation purposes. It is also possible to add
227
     * arbitrary arguments as with every other class method.
228
     *
229
     * @param TODO
230
     */
231
    public function __construct()
232
    {
233
        $this->initWorkflow();
234
    }
235
    
236
    /**
237
     * Returns the _object type.
238
     *
239
     * @return string
240
     */
241
    public function get_objectType()
242
    {
243
        return $this->_objectType;
244
    }
245
    
246
    /**
247
     * Sets the _object type.
248
     *
249
     * @param string $_objectType
250
     *
251
     * @return void
252
     */
253
    public function set_objectType($_objectType)
254
    {
255
        $this->_objectType = $_objectType;
256
    }
257
    
258
    /**
259
     * Returns the _bypass validation.
260
     *
261
     * @return boolean
262
     */
263
    public function get_bypassValidation()
264
    {
265
        return $this->_bypassValidation;
266
    }
267
    
268
    /**
269
     * Sets the _bypass validation.
270
     *
271
     * @param boolean $_bypassValidation
272
     *
273
     * @return void
274
     */
275
    public function set_bypassValidation($_bypassValidation)
276
    {
277
        $this->_bypassValidation = $_bypassValidation;
278
    }
279
    
280
    /**
281
     * Returns the id.
282
     *
283
     * @return integer
284
     */
285
    public function getId()
286
    {
287
        return $this->id;
288
    }
289
    
290
    /**
291
     * Sets the id.
292
     *
293
     * @param integer $id
294
     *
295
     * @return void
296
     */
297
    public function setId($id)
298
    {
299
        $this->id = intval($id);
300
    }
301
    
302
    /**
303
     * Returns the workflow state.
304
     *
305
     * @return string
306
     */
307
    public function getWorkflowState()
308
    {
309
        return $this->workflowState;
310
    }
311
    
312
    /**
313
     * Sets the workflow state.
314
     *
315
     * @param string $workflowState
316
     *
317
     * @return void
318
     */
319
    public function setWorkflowState($workflowState)
320
    {
321
        $this->workflowState = isset($workflowState) ? $workflowState : '';
322
    }
323
    
324
    /**
325
     * Returns the route type.
326
     *
327
     * @return string
328
     */
329
    public function getRouteType()
330
    {
331
        return $this->routeType;
332
    }
333
    
334
    /**
335
     * Sets the route type.
336
     *
337
     * @param string $routeType
338
     *
339
     * @return void
340
     */
341
    public function setRouteType($routeType)
342
    {
343
        $this->routeType = isset($routeType) ? $routeType : '';
344
    }
345
    
346
    /**
347
     * Returns the replaced route name.
348
     *
349
     * @return string
350
     */
351
    public function getReplacedRouteName()
352
    {
353
        return $this->replacedRouteName;
354
    }
355
    
356
    /**
357
     * Sets the replaced route name.
358
     *
359
     * @param string $replacedRouteName
360
     *
361
     * @return void
362
     */
363
    public function setReplacedRouteName($replacedRouteName)
364
    {
365
        $this->replacedRouteName = $replacedRouteName;
366
    }
367
    
368
    /**
369
     * Returns the bundle.
370
     *
371
     * @return string
372
     */
373
    public function getBundle()
374
    {
375
        return $this->bundle;
376
    }
377
    
378
    /**
379
     * Sets the bundle.
380
     *
381
     * @param string $bundle
382
     *
383
     * @return void
384
     */
385
    public function setBundle($bundle)
386
    {
387
        $this->bundle = isset($bundle) ? $bundle : '';
388
    }
389
    
390
    /**
391
     * Returns the controller.
392
     *
393
     * @return string
394
     */
395
    public function getController()
396
    {
397
        return $this->controller;
398
    }
399
    
400
    /**
401
     * Sets the controller.
402
     *
403
     * @param string $controller
404
     *
405
     * @return void
406
     */
407
    public function setController($controller)
408
    {
409
        $this->controller = isset($controller) ? $controller : '';
410
    }
411
    
412
    /**
413
     * Returns the action.
414
     *
415
     * @return string
416
     */
417
    public function getAction()
418
    {
419
        return $this->action;
420
    }
421
    
422
    /**
423
     * Sets the action.
424
     *
425
     * @param string $action
426
     *
427
     * @return void
428
     */
429
    public function setAction($action)
430
    {
431
        $this->action = isset($action) ? $action : '';
432
    }
433
    
434
    /**
435
     * Returns the path.
436
     *
437
     * @return string
438
     */
439
    public function getPath()
440
    {
441
        return $this->path;
442
    }
443
    
444
    /**
445
     * Sets the path.
446
     *
447
     * @param string $path
448
     *
449
     * @return void
450
     */
451
    public function setPath($path)
452
    {
453
        $this->path = isset($path) ? $path : '';
454
    }
455
    
456
    /**
457
     * Returns the host.
458
     *
459
     * @return string
460
     */
461
    public function getHost()
462
    {
463
        return $this->host;
464
    }
465
    
466
    /**
467
     * Sets the host.
468
     *
469
     * @param string $host
470
     *
471
     * @return void
472
     */
473
    public function setHost($host)
474
    {
475
        $this->host = $host;
476
    }
477
    
478
    /**
479
     * Returns the schemes.
480
     *
481
     * @return string
482
     */
483
    public function getSchemes()
484
    {
485
        return $this->schemes;
486
    }
487
    
488
    /**
489
     * Sets the schemes.
490
     *
491
     * @param string $schemes
492
     *
493
     * @return void
494
     */
495
    public function setSchemes($schemes)
496
    {
497
        $this->schemes = isset($schemes) ? $schemes : '';
498
    }
499
    
500
    /**
501
     * Returns the methods.
502
     *
503
     * @return string
504
     */
505
    public function getMethods()
506
    {
507
        return $this->methods;
508
    }
509
    
510
    /**
511
     * Sets the methods.
512
     *
513
     * @param string $methods
514
     *
515
     * @return void
516
     */
517
    public function setMethods($methods)
518
    {
519
        $this->methods = isset($methods) ? $methods : '';
520
    }
521
    
522
    /**
523
     * Returns the prepend bundle prefix.
524
     *
525
     * @return boolean
526
     */
527
    public function getPrependBundlePrefix()
528
    {
529
        return $this->prependBundlePrefix;
530
    }
531
    
532
    /**
533
     * Sets the prepend bundle prefix.
534
     *
535
     * @param boolean $prependBundlePrefix
536
     *
537
     * @return void
538
     */
539
    public function setPrependBundlePrefix($prependBundlePrefix)
540
    {
541
        if ($prependBundlePrefix !== $this->prependBundlePrefix) {
542
            $this->prependBundlePrefix = (bool)$prependBundlePrefix;
543
        }
544
    }
545
    
546
    /**
547
     * Returns the translatable.
548
     *
549
     * @return boolean
550
     */
551
    public function getTranslatable()
552
    {
553
        return $this->translatable;
554
    }
555
    
556
    /**
557
     * Sets the translatable.
558
     *
559
     * @param boolean $translatable
560
     *
561
     * @return void
562
     */
563
    public function setTranslatable($translatable)
564
    {
565
        if ($translatable !== $this->translatable) {
566
            $this->translatable = (bool)$translatable;
567
        }
568
    }
569
    
570
    /**
571
     * Returns the translation prefix.
572
     *
573
     * @return string
574
     */
575
    public function getTranslationPrefix()
576
    {
577
        return $this->translationPrefix;
578
    }
579
    
580
    /**
581
     * Sets the translation prefix.
582
     *
583
     * @param string $translationPrefix
584
     *
585
     * @return void
586
     */
587
    public function setTranslationPrefix($translationPrefix)
588
    {
589
        $this->translationPrefix = $translationPrefix;
590
    }
591
    
592
    /**
593
     * Returns the defaults.
594
     *
595
     * @return array
596
     */
597
    public function getDefaults()
598
    {
599
        return $this->defaults;
600
    }
601
    
602
    /**
603
     * Sets the defaults.
604
     *
605
     * @param array $defaults
606
     *
607
     * @return void
608
     */
609
    public function setDefaults($defaults)
610
    {
611
        $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...
612
    }
613
    
614
    /**
615
     * Returns the requirements.
616
     *
617
     * @return array
618
     */
619
    public function getRequirements()
620
    {
621
        return $this->requirements;
622
    }
623
    
624
    /**
625
     * Sets the requirements.
626
     *
627
     * @param array $requirements
628
     *
629
     * @return void
630
     */
631
    public function setRequirements($requirements)
632
    {
633
        $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...
634
    }
635
    
636
    /**
637
     * Returns the condition.
638
     *
639
     * @return string
640
     */
641
    public function getCondition()
642
    {
643
        return $this->condition;
644
    }
645
    
646
    /**
647
     * Sets the condition.
648
     *
649
     * @param string $condition
650
     *
651
     * @return void
652
     */
653
    public function setCondition($condition)
654
    {
655
        $this->condition = $condition;
656
    }
657
    
658
    /**
659
     * Returns the description.
660
     *
661
     * @return string
662
     */
663
    public function getDescription()
664
    {
665
        return $this->description;
666
    }
667
    
668
    /**
669
     * Sets the description.
670
     *
671
     * @param string $description
672
     *
673
     * @return void
674
     */
675
    public function setDescription($description)
676
    {
677
        $this->description = $description;
678
    }
679
    
680
    /**
681
     * Returns the sort.
682
     *
683
     * @return integer
684
     */
685
    public function getSort()
686
    {
687
        return $this->sort;
688
    }
689
    
690
    /**
691
     * Sets the sort.
692
     *
693
     * @param integer $sort
694
     *
695
     * @return void
696
     */
697
    public function setSort($sort)
698
    {
699
        $this->sort = intval($sort);
700
    }
701
    
702
    /**
703
     * Returns the group.
704
     *
705
     * @return string
706
     */
707
    public function getGroup()
708
    {
709
        return $this->group;
710
    }
711
    
712
    /**
713
     * Sets the group.
714
     *
715
     * @param string $group
716
     *
717
     * @return void
718
     */
719
    public function setGroup($group)
720
    {
721
        $this->group = isset($group) ? $group : '';
722
    }
723
    
724
    
725
    
726
    
727
    /**
728
     * Returns the formatted title conforming to the display pattern
729
     * specified for this entity.
730
     *
731
     * @return string The display title
732
     */
733
    public function getTitleFromDisplayPattern()
734
    {
735
        $listHelper = ServiceUtil::get('zikula_routes_module.listentries_helper');
0 ignored issues
show
Unused Code introduced by
$listHelper is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
736
    
737
        $formattedTitle = ''
738
                . $this->getPath()
739
                . ' ('
740
                . $this->getSort()
741
                . ')';
742
    
743
        return $formattedTitle;
744
    }
745
    
746
    
747
    /**
748
     * Returns a list of possible choices for the workflowState list field.
749
     * This method is used for validation.
750
     *
751
     * @return array List of allowed choices
752
     */
753
    public static function getWorkflowStateAllowedValues()
754
    {
755
        $serviceManager = ServiceUtil::getManager();
756
        $helper = $serviceManager->get('zikula_routes_module.listentries_helper');
757
        $listEntries = $helper->getWorkflowStateEntriesForRoute();
758
    
759
        $allowedValues = ['initial'];
760
        foreach ($listEntries as $entry) {
761
            $allowedValues[] = $entry['value'];
762
        }
763
    
764
        return $allowedValues;
765
    }
766
    
767
    /**
768
     * Returns a list of possible choices for the routeType list field.
769
     * This method is used for validation.
770
     *
771
     * @return array List of allowed choices
772
     */
773
    public static function getRouteTypeAllowedValues()
774
    {
775
        $serviceManager = ServiceUtil::getManager();
776
        $helper = $serviceManager->get('zikula_routes_module.listentries_helper');
777
        $listEntries = $helper->getRouteTypeEntriesForRoute();
778
    
779
        $allowedValues = [];
780
        foreach ($listEntries as $entry) {
781
            $allowedValues[] = $entry['value'];
782
        }
783
    
784
        return $allowedValues;
785
    }
786
    
787
    /**
788
     * @Assert\Callback()
789
     */
790 View Code Duplication
    public function isSchemesValueAllowed(ExecutionContextInterface $context)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
791
    {
792
        $serviceManager = ServiceUtil::getManager();
793
        $helper = $serviceManager->get('zikula_routes_module.listentries_helper');
794
        $listEntries = $helper->getSchemesEntriesForRoute();
795
    
796
        $allowedValues = [];
797
        foreach ($listEntries as $entry) {
798
            $allowedValues[] = $entry['value'];
799
        }
800
    
801
        $selected = explode('###', $this->schemes);
802
        foreach ($selected as $value) {
803
            if ($value == '') {
804
                continue;
805
            }
806
            if (!in_array($value, $allowedValues, true)) {
807
                $context->buildViolation($serviceManager->get('translator.default')->__('Invalid value provided'))
808
                    ->atPath('schemes')
809
                    ->addViolation();
810
            }
811
        }
812
    }
813
    
814
    /**
815
     * @Assert\Callback()
816
     */
817 View Code Duplication
    public function isMethodsValueAllowed(ExecutionContextInterface $context)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
818
    {
819
        $serviceManager = ServiceUtil::getManager();
820
        $helper = $serviceManager->get('zikula_routes_module.listentries_helper');
821
        $listEntries = $helper->getMethodsEntriesForRoute();
822
    
823
        $allowedValues = [];
824
        foreach ($listEntries as $entry) {
825
            $allowedValues[] = $entry['value'];
826
        }
827
    
828
        $selected = explode('###', $this->methods);
829
        foreach ($selected as $value) {
830
            if ($value == '') {
831
                continue;
832
            }
833
            if (!in_array($value, $allowedValues, true)) {
834
                $context->buildViolation($serviceManager->get('translator.default')->__('Invalid value provided'))
835
                    ->atPath('methods')
836
                    ->addViolation();
837
            }
838
        }
839
    }
840
    
841
    /**
842
     * Start validation and raise exception if invalid data is found.
843
     *
844
     * @return boolean Whether everything is valid or not
845
     */
846
    public function validate()
847
    {
848
        if (true === $this->_bypassValidation) {
849
            return true;
850
        }
851
    
852
        $validator = ServiceUtil::get('validator');
853
        $errors = $validator->validate($this);
854
    
855
        if (count($errors) > 0) {
856
            $flashBag = ServiceUtil::get('session')->getFlashBag();
857
            foreach ($errors as $error) {
858
                $flashBag->add('error', $error->getMessage());
859
            }
860
    
861
            return false;
862
        }
863
    
864
        return true;
865
    }
866
    
867
    /**
868
     * Return entity data in JSON format.
869
     *
870
     * @return string JSON-encoded data
871
     */
872
    public function toJson()
873
    {
874
        return json_encode($this->toArray());
875
    }
876
    
877
    /**
878
     * Creates url arguments array for easy creation of display urls.
879
     *
880
     * @return array The resulting arguments list
881
     */
882
    public function createUrlArgs()
883
    {
884
        $args = [];
885
    
886
        $args['id'] = $this['id'];
887
    
888
        if (property_exists($this, 'slug')) {
889
            $args['slug'] = $this['slug'];
890
        }
891
    
892
        return $args;
893
    }
894
    
895
    /**
896
     * Create concatenated identifier string (for composite keys).
897
     *
898
     * @return String concatenated identifiers
899
     */
900
    public function createCompositeIdentifier()
901
    {
902
        $itemId = $this['id'];
903
    
904
        return $itemId;
905
    }
906
    
907
    /**
908
     * Determines whether this entity supports hook subscribers or not.
909
     *
910
     * @return boolean
911
     */
912
    public function supportsHookSubscribers()
913
    {
914
        return false;
915
    }
916
    
917
    /**
918
     * Returns an array of all related objects that need to be persisted after clone.
919
     * 
920
     * @param array $objects The objects are added to this array. Default: []
921
     * 
922
     * @return array of entity objects
923
     */
924
    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...
925
    {
926
        return [];
927
    }
928
    
929
    /**
930
     * ToString interceptor implementation.
931
     * This method is useful for debugging purposes.
932
     *
933
     * @return string The output string for this entity
934
     */
935
    public function __toString()
936
    {
937
        return 'Route ' . $this->createCompositeIdentifier() . ': ' . $this->getTitleFromDisplayPattern();
938
    }
939
    
940
    /**
941
     * Clone interceptor implementation.
942
     * This method is for example called by the reuse functionality.
943
     * Performs a quite simple shallow copy.
944
     *
945
     * See also:
946
     * (1) http://docs.doctrine-project.org/en/latest/cookbook/implementing-wakeup-or-clone.html
947
     * (2) http://www.php.net/manual/en/language.oop5.cloning.php
948
     * (3) http://stackoverflow.com/questions/185934/how-do-i-create-a-copy-of-an-object-in-php
949
     */
950
    public function __clone()
951
    {
952
        // if the entity has no identity do nothing, do NOT throw an exception
953
        if (!($this->id)) {
954
            return;
955
        }
956
    
957
        // otherwise proceed
958
    
959
        // unset identifiers
960
        $this->setId(0);
961
    
962
        // reset workflow
963
        $this->resetWorkflow();
964
    
965
        $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...
966
        $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...
967
        $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...
968
        $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...
969
    
970
    }
971
}
972