Issues (3099)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

AdminBundle/Entity/GroupPropertiesTrait.php (1 issue)

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
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
Should the type for parameter $role not be string|null?

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.

Loading history...
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