This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminBundle\Entity; |
||
4 | |||
5 | use Doctrine\Common\Collections\ArrayCollection; |
||
6 | use Doctrine\Common\Collections\Collection; |
||
7 | use Doctrine\ORM\Mapping as ORM; |
||
8 | use FOS\UserBundle\Model\GroupInterface; |
||
9 | use InvalidArgumentException; |
||
10 | use Symfony\Component\Validator\Constraints as Assert; |
||
11 | use Symfony\Component\Validator\Context\ExecutionContextInterface; |
||
12 | |||
13 | /** |
||
14 | * @final |
||
15 | * |
||
16 | * @internal |
||
17 | */ |
||
18 | trait GroupPropertiesTrait |
||
19 | { |
||
20 | /** |
||
21 | * @ORM\Id |
||
22 | * @ORM\Column(type="integer") |
||
23 | * @ORM\GeneratedValue(strategy="AUTO") |
||
24 | */ |
||
25 | protected $id; |
||
26 | |||
27 | /** |
||
28 | * @Assert\NotBlank() |
||
29 | * @ORM\Column(type="string") |
||
30 | */ |
||
31 | protected $name; |
||
32 | |||
33 | /** |
||
34 | * @ORM\ManyToMany(targetEntity="Role") |
||
35 | * @ORM\JoinTable(name="kuma_groups_roles", |
||
36 | * joinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}, |
||
37 | * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")} |
||
38 | * ) |
||
39 | */ |
||
40 | protected $roles; |
||
41 | |||
42 | /** |
||
43 | * Construct a new group |
||
44 | * |
||
45 | * @param string $name Name of the group |
||
46 | */ |
||
47 | 13 | public function __construct($name = '') |
|
48 | { |
||
49 | 13 | $this->name = $name; |
|
50 | 13 | $this->roles = new ArrayCollection(); |
|
51 | 13 | } |
|
52 | |||
53 | /** |
||
54 | * Get id |
||
55 | * |
||
56 | * @return int |
||
57 | */ |
||
58 | 1 | public function getId() |
|
59 | { |
||
60 | 1 | return $this->id; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Get string representation of object |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | 1 | public function __toString() |
|
69 | { |
||
70 | 1 | return $this->getName(); |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Returns an array of strings (needed because Symfony ACL doesn't support using RoleInterface yet) |
||
75 | * |
||
76 | * @return array |
||
77 | */ |
||
78 | 4 | public function getRoles() |
|
79 | { |
||
80 | 4 | $result = array(); |
|
81 | /* @var $role RoleInterface */ |
||
82 | 4 | foreach ($this->roles as $role) { |
|
83 | 3 | $result[] = $role->getRole(); |
|
84 | } |
||
85 | |||
86 | 4 | return $result; |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * Returns the true ArrayCollection of Roles. |
||
91 | * |
||
92 | * @return ArrayCollection |
||
93 | */ |
||
94 | 2 | public function getRolesCollection() |
|
95 | { |
||
96 | 2 | return $this->roles; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * Pass a string, get the desired Role object or null. |
||
101 | * |
||
102 | * @param string $role |
||
0 ignored issues
–
show
|
|||
103 | * |
||
104 | * @return Role|null |
||
105 | */ |
||
106 | 7 | public function getRole($role = null) |
|
107 | { |
||
108 | /* @var $roleItem RoleInterface */ |
||
109 | 7 | foreach ($this->roles as $roleItem) { |
|
110 | 4 | if ($role == $roleItem->getRole()) { |
|
111 | 3 | return $roleItem; |
|
112 | } |
||
113 | } |
||
114 | |||
115 | 7 | return null; |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * Pass a string, checks if we have that Role. Same functionality as getRole() except it returns a boolean. |
||
120 | * |
||
121 | * @param string $role |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | 7 | public function hasRole($role) |
|
126 | { |
||
127 | 7 | if ($this->getRole($role)) { |
|
128 | 2 | return true; |
|
129 | } |
||
130 | |||
131 | 7 | return false; |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Adds a Role object to the ArrayCollection. Can't type hint due to interface so throws Exception. |
||
136 | * |
||
137 | * @param Role $role |
||
138 | * |
||
139 | * @return GroupInterface |
||
140 | * |
||
141 | * @throws InvalidArgumentException |
||
142 | */ |
||
143 | 8 | public function addRole($role) |
|
144 | { |
||
145 | 8 | if (!$role instanceof Role) { |
|
146 | 1 | throw new InvalidArgumentException('addRole takes a Role object as the parameter'); |
|
147 | } |
||
148 | |||
149 | 7 | if (!$this->hasRole($role->getRole())) { |
|
150 | 7 | $this->roles->add($role); |
|
151 | } |
||
152 | |||
153 | 7 | return $this; |
|
154 | } |
||
155 | |||
156 | /** |
||
157 | * Pass a string, remove the Role object from collection. |
||
158 | * |
||
159 | * @param string $role |
||
160 | * |
||
161 | * @return GroupInterface |
||
162 | */ |
||
163 | 1 | public function removeRole($role) |
|
164 | { |
||
165 | 1 | $roleElement = $this->getRole($role); |
|
166 | 1 | if ($roleElement) { |
|
167 | 1 | $this->roles->removeElement($roleElement); |
|
168 | } |
||
169 | |||
170 | 1 | return $this; |
|
171 | } |
||
172 | |||
173 | /** |
||
174 | * Pass an ARRAY of Role objects and will clear the collection and re-set it with new Roles. |
||
175 | * |
||
176 | * @param Role[] $roles array of Role objects |
||
177 | * |
||
178 | * @return GroupInterface |
||
179 | */ |
||
180 | 1 | public function setRoles(array $roles) |
|
181 | { |
||
182 | 1 | $this->roles->clear(); |
|
183 | 1 | foreach ($roles as $role) { |
|
184 | 1 | $this->addRole($role); |
|
185 | } |
||
186 | |||
187 | 1 | return $this; |
|
188 | } |
||
189 | |||
190 | /** |
||
191 | * Directly set the ArrayCollection of Roles. Type hinted as Collection which is the parent of (Array|Persistent)Collection. |
||
192 | * |
||
193 | * @param Collection $collection |
||
194 | * |
||
195 | * @return GroupInterface |
||
196 | */ |
||
197 | 1 | public function setRolesCollection(Collection $collection) |
|
198 | { |
||
199 | 1 | $this->roles = $collection; |
|
200 | |||
201 | 1 | return $this; |
|
202 | } |
||
203 | |||
204 | /** |
||
205 | * Return the name of the group |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | 2 | public function getName() |
|
210 | { |
||
211 | 2 | return $this->name; |
|
212 | } |
||
213 | |||
214 | /** |
||
215 | * Set the name of the group |
||
216 | * |
||
217 | * @param string $name New name of the group |
||
218 | * |
||
219 | * @return GroupInterface |
||
220 | */ |
||
221 | 1 | public function setName($name) |
|
222 | { |
||
223 | 1 | $this->name = $name; |
|
224 | |||
225 | 1 | return $this; |
|
226 | } |
||
227 | |||
228 | /** |
||
229 | * @Assert\Callback |
||
230 | * |
||
231 | * @param ExecutionContextInterface $context |
||
232 | */ |
||
233 | 2 | public function isGroupValid(ExecutionContextInterface $context) |
|
234 | { |
||
235 | 2 | if (!(\count($this->getRoles()) > 0)) { |
|
236 | $context |
||
237 | 1 | ->buildViolation('errors.group.selectone', array()) |
|
238 | 1 | ->atPath('rolesCollection') |
|
239 | 1 | ->addViolation(); |
|
240 | } |
||
241 | 2 | } |
|
242 | } |
||
243 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.