Passed
Push — master ( 3a2b95...eadeac )
by Thalles
03:46 queued 01:58
created

UserInfo::_getPermissions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace ThallesDella\GateKeeper;
4
5
use ThallesDella\GateKeeper\Roles\Roles;
6
7
/**
8
 * Gate Keeper | Class UserInfo [ GATE KEEPER ]
9
 *
10
 * @category GateKeeper
11
 * @package  ThallesDella\GateKeeper
12
 * @author   Thalles D. koester <[email protected]>
13
 * @license  https://choosealicense.com/licenses/mit/ MIT
14
 * @link     https://github.com/thallesdella/gate-keeper
15
 */
16
class UserInfo
17
{
18
    /**
19
     * User role name
20
     *
21
     * @var string
22
     */
23
    public $role;
24
    
25
    /**
26
     * User permissions
27
     *
28
     * @var array
29
     */
30
    public $permissions;
31
    
32
    /**
33
     * Object roles
34
     *
35
     * @var Roles
36
     */
37
    private $roles;
38
    
39
    /**
40
     * UserInfo constructor.
41
     *
42
     * @param string|null $userRole Role of the user
43
     * @param Roles       $roles    Roles object
44
     */
45
    public function __construct(?string $userRole, Roles $roles)
46
    {
47
        $this->role = (!empty($userRole) ? $userRole : 'guest');
48
        $this->roles = $roles;
49
        $this->permissions = $this->getPermissions();
50
    }
51
    
52
    /**
53
     * Get permissions por this user
54
     *
55
     * @return array
56
     */
57
    private function getPermissions(): array
58
    {
59
        if ($this->role == 'guest') {
60
            return [];
61
        }
62
        
63
        return $this->roles->getPermissions($this);
64
    }
65
}