Role::__get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4286
cc 2
eloc 5
nc 2
nop 1
1
<?php namespace Modules\User\Entities\Usher;
2
3
use Doctrine\Common\Collections\ArrayCollection;
4
use Doctrine\ORM\Mapping as ORM;
5
use Maatwebsite\Usher\Contracts\Roles\Role as RoleInterface;
6
use Maatwebsite\Usher\Domain\Roles\Role as UsherRole;
7
8
/**
9
 * @ORM\Entity
10
 * @ORM\Table(name="roles")
11
 * @ORM\HasLifecycleCallbacks()
12
 */
13
class Role extends UsherRole implements RoleInterface
14
{
15
    /**
16
     * @ORM\ManyToMany(targetEntity="User", mappedBy="roles")
17
     * @var ArrayCollection|\Maatwebsite\Usher\Contracts\Users\User[]
18
     **/
19
    protected $users;
20
21
    /**
22
     * @return ArrayCollection
23
     */
24
    public function getUsers()
25
    {
26
        return $this->users;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->users; of type Doctrine\Common\Collecti...\Contracts\Users\User[] adds the type Maatwebsite\Usher\Contracts\Users\User[] to the return on line 26 which is incompatible with the return type documented by Modules\User\Entities\Usher\Role::getUsers of type Doctrine\Common\Collections\ArrayCollection.
Loading history...
27
    }
28
29
    public function users()
30
    {
31
        return $this->getUsers();
32
    }
33
34
    /**
35
     * @param ArrayCollection $users
36
     */
37
    public function setUsers(ArrayCollection $users)
38
    {
39
        $this->users = $users;
40
    }
41
42
    /**
43
     * @param $attribute
44
     * @return null|string
45
     */
46
    public function __get($attribute)
47
    {
48
        $method = 'get' . studly_case($attribute);
49
50
        if (method_exists($this, $method)) {
51
            return $this->{$method}();
52
        }
53
54
        return null;
55
    }
56
57
    /**
58
     * @param $attribute
59
     * @return bool
60
     */
61
    public function __isset($attribute)
62
    {
63
        $method = 'get' . studly_case($attribute);
64
65
        if (method_exists($this, $method)) {
66
            return true;
67
        }
68
69
        return false;
70
    }
71
}
72