Completed
Push — master ( b9c485...94fed1 )
by Michał
13:51
created

src/Sylius/Component/Rbac/Model/Permission.php (1 issue)

mismatching argument types.

Documentation Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Rbac\Model;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Sylius\Component\Resource\Model\TimestampableTrait;
17
18
/**
19
 * Default permission implementation.
20
 *
21
 * @author Paweł Jędrzejewski <[email protected]>
22
 */
23
class Permission implements PermissionInterface
24
{
25
    use TimestampableTrait;
26
27
    /**
28
     * @var mixed
29
     */
30
    protected $id;
31
32
    /**
33
     * @var string
34
     */
35
    protected $code;
36
37
    /**
38
     * @var string
39
     */
40
    protected $description;
41
42
    /**
43
     * @var null|PermissionInterface
44
     */
45
    protected $parent;
46
47
    /**
48
     * @var Collection|PermissionInterface[]
49
     */
50
    protected $children;
51
52
    /**
53
     * Required by DoctrineExtensions.
54
     *
55
     * @var int
56
     */
57
    protected $left;
58
59
    /**
60
     * Required by DoctrineExtensions.
61
     *
62
     * @var int
63
     */
64
    protected $right;
65
66
    /**
67
     * Required by DoctrineExtensions.
68
     *
69
     * @var int
70
     */
71
    protected $level;
72
73
    public function __construct()
74
    {
75
        $this->children = new ArrayCollection();
76
        $this->createdAt = new \DateTime();
77
    }
78
79
    public function __toString()
80
    {
81
        return $this->description;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function getId()
88
    {
89
        return $this->id;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function getCode()
96
    {
97
        return $this->code;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function setCode($code)
104
    {
105
        $this->code = $code;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function getDescription()
112
    {
113
        return $this->description;
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119
    public function setDescription($description)
120
    {
121
        $this->description = $description;
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127
    public function getParent()
128
    {
129
        return $this->parent;
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135
    public function setParent(PermissionInterface $permission = null)
136
    {
137
        $this->parent = $permission;
138
    }
139
140
    /**
141
     * {@inheritdoc}
142
     */
143
    public function getChildren()
144
    {
145
        return $this->children;
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     */
151
    public function hasChildren()
152
    {
153
        return !$this->children->isEmpty();
154
    }
155
156
    /**
157
     * {@inheritdoc}
158
     */
159
    public function addChild(PermissionInterface $permission)
160
    {
161
        if (!$this->hasChild($permission)) {
162
            $permission->setParent($this);
163
            $this->children->add($permission);
164
        }
165
    }
166
167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function removeChild(PermissionInterface $permission)
171
    {
172
        if ($this->hasChild($permission)) {
173
            $permission->setParent(null);
0 ignored issues
show
null is of type null, but the function expects a object<Sylius\Component\...el\PermissionInterface>.

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...
174
            $this->children->removeElement($permission);
175
        }
176
    }
177
178
    /**
179
     * {@inheritdoc}
180
     */
181
    public function hasChild(PermissionInterface $permission)
182
    {
183
        return $this->children->contains($permission);
184
    }
185
186
    /**
187
     * {@inheritdoc}
188
     */
189
    public function getLeft()
190
    {
191
        return $this->left;
192
    }
193
194
    /**
195
     * {@inheritdoc}
196
     */
197
    public function setLeft($left)
198
    {
199
        $this->left = $left;
200
    }
201
202
    /**
203
     * {@inheritdoc}
204
     */
205
    public function getRight()
206
    {
207
        return $this->right;
208
    }
209
210
    /**
211
     * {@inheritdoc}
212
     */
213
    public function setRight($right)
214
    {
215
        $this->right = $right;
216
    }
217
218
    /**
219
     * {@inheritdoc}
220
     */
221
    public function getLevel()
222
    {
223
        return $this->level;
224
    }
225
226
    /**
227
     * {@inheritdoc}
228
     */
229
    public function setLevel($level)
230
    {
231
        $this->level = $level;
232
    }
233
}
234