Completed
Push — master ( 0fb6c2...a0d538 )
by Adam
19:02
created

Page::getLayout()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 4
Code Lines 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\CmsBundle\Entity;
14
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\Common\Collections\Collection;
17
use Knp\DoctrineBehaviors\Model\Blameable\Blameable;
18
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;
19
use Knp\DoctrineBehaviors\Model\Translatable\Translatable;
20
use WellCommerce\Bundle\AppBundle\Entity\ShopCollectionAwareTrait;
21
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Identifiable;
22
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Sortable;
23
use WellCommerce\Bundle\CoreBundle\Entity\EntityInterface;
24
use WellCommerce\Extra\CmsBundle\Entity\PageExtraTrait;
25
26
/**
27
 * Class Page
28
 *
29
 * @author  Adam Piotrowski <[email protected]>
30
 */
31
class Page implements EntityInterface
32
{
33
    use Identifiable;
34
    use Sortable;
35
    use Translatable;
36
    use Timestampable;
37
    use Blameable;
38
    use ShopCollectionAwareTrait;
39
    use PageExtraTrait;
40
    
41
    protected $publish       = true;
42
    protected $section       = '';
43
    protected $redirectType  = 1;
44
    protected $redirectUrl   = '';
45
    protected $redirectRoute = '';
46
    protected $layout        = [];
47
    
48
    /**
49
     * @var Page|null
50
     */
51
    protected $parent;
52
    
53
    /**
54
     * @var Collection
55
     */
56
    protected $clientGroups;
57
    
58
    /**
59
     * @var Collection
60
     */
61
    protected $children;
62
    
63
    public function __construct()
64
    {
65
        $this->clientGroups = new ArrayCollection();
66
        $this->shops        = new ArrayCollection();
67
    }
68
    
69
    public function getPublish(): bool
70
    {
71
        return $this->publish;
72
    }
73
    
74
    public function setPublish(bool $publish)
75
    {
76
        $this->publish = $publish;
77
    }
78
    
79
    public function getParent()
80
    {
81
        return $this->parent;
82
    }
83
    
84
    public function setParent(self $parent = null)
85
    {
86
        $this->parent = $parent;
0 ignored issues
show
Documentation Bug introduced by Adam Piotrowski
It seems like $parent can also be of type object<self>. However, the property $parent is declared as type object<WellCommerce\Bund...undle\Entity\Page>|null. 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...
87
    }
88
    
89
    public function getChildren(): Collection
90
    {
91
        return $this->children;
92
    }
93
    
94
    public function addChild(self $child)
95
    {
96
        $this->children[] = $child;
97
        $child->setParent($this);
98
    }
99
    
100
    public function getRedirectRoute()
101
    {
102
        return $this->redirectRoute;
103
    }
104
    
105
    public function setRedirectRoute($redirectRoute)
106
    {
107
        $this->redirectRoute = $redirectRoute;
108
    }
109
    
110
    public function getRedirectUrl()
111
    {
112
        return $this->redirectUrl;
113
    }
114
    
115
    public function setRedirectUrl($redirectUrl)
116
    {
117
        $this->redirectUrl = $redirectUrl;
118
    }
119
    
120
    public function getClientGroups(): Collection
121
    {
122
        return $this->clientGroups;
123
    }
124
    
125
    public function setClientGroups(Collection $clientGroups)
126
    {
127
        $this->clientGroups = $clientGroups;
128
    }
129
    
130
    public function prePersist()
131
    {
132
        $redirectType = $this->getRedirectType();
133
        switch ($redirectType) {
134
            case 0:
135
                $this->setRedirectRoute(null);
136
                $this->setRedirectUrl(null);
137
                break;
138
            case 1:
139
                $this->setRedirectRoute(null);
140
                break;
141
            case 2:
142
                $this->setRedirectUrl(null);
143
                break;
144
        }
145
    }
146
    
147
    public function getRedirectType(): int
148
    {
149
        return $this->redirectType;
150
    }
151
    
152
    public function setRedirectType(int $redirectType)
153
    {
154
        $this->redirectType = $redirectType;
155
    }
156
    
157
    public function getSection(): string
158
    {
159
        return $this->section;
160
    }
161
    
162
    public function setSection(string $section)
163
    {
164
        $this->section = $section;
165
    }
166
    
167
    public function getLayout(): array
168
    {
169
        return $this->layout;
170
    }
171
    
172
    public function setLayout(array $layout)
173
    {
174
        $this->layout = $layout;
175
    }
176
    
177
    public function translate($locale = null, $fallbackToDefault = true): PageTranslation
178
    {
179
        return $this->doTranslate($locale, $fallbackToDefault);
180
    }
181
}
182