Completed
Push — master ( 926740...1237f3 )
by Daniel
91:04 queued 79:23
created

RestrictedResourceTrait::getSecurityRoles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\Entity;
6
7
use Doctrine\ORM\Mapping as ORM;
8
9
trait RestrictedResourceTrait
10
{
11
    /**
12
     * @ORM\Column(type="json_array", nullable=true)
13
     * @var array|null
14
     */
15
    protected $securityRoles;
16
17
    public function getSecurityRoles(): ?array
18
    {
19
        return $this->securityRoles;
20
    }
21
22
    /**
23
     * @param string $securityRole
24
     * @return static
25
     */
26
    public function addSecurityRole(string $securityRole)
27
    {
28
        $this->securityRoles[] = $securityRole;
29
        return $this;
30
    }
31
32
    /**
33
     * @param array|null $securityRoles
34
     * @return static
35
     */
36
    public function setSecurityRoles(?array $securityRoles)
37
    {
38
        if (!$securityRoles) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $securityRoles of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
39
            $this->securityRoles = $securityRoles;
40
            return $this;
41
        }
42
        $this->securityRoles = [];
43
        foreach ($securityRoles as $securityRole) {
44
            $this->addSecurityRole($securityRole);
45
        }
46
        return $this;
47
    }
48
}
49