Completed
Push — b0.25.0 ( b1670c...6acf42 )
by Sebastian
05:31
created

Role::setUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * Linna Framework.
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2018, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\Authorization;
13
14
use Linna\DataMapper\DomainObjectAbstract;
15
16
/**
17
 * Role.
18
 */
19
class Role extends DomainObjectAbstract
20
{
21
    use PermissionTrait;
22
23
    /**
24
     * @var string Group name
25
     */
26
    public $name = '';
27
28
    /**
29
     * @var string Group description
30
     */
31
    public $description = '';
32
33
    /**
34
     * @var int It say if group is active or not
35
     */
36
    public $active = 0;
37
38
    /**
39
     * @var array Contain users in group
40
     */
41
    private $users = [];
42
43
    /**
44
     * @var string Last update
45
     */
46
    public $lastUpdate = '';
47
48
    /**
49
     * Constructor.
50
     */
51 1
    public function __construct(array $users = [], array $permissions = [])
52
    {
53 1
        $this->users = $users;
54 1
        $this->permission = $permissions;
55
56
        //set required type
57 1
        settype($this->objectId, 'integer');
58 1
        settype($this->active, 'integer');
59 1
    }
60
61
    /**
62
     * Check if an user is in role.
63
     *
64
     * @param string $user
65
     *
66
     * @return bool
67
     */
68
    public function isUserInRole(string $user): bool
69
    {
70
        foreach ($this->users as $ownUser) {
71
            if ($ownUser->name === $user) {
72
                return true;
73
            }
74
        }
75
76
        return false;
77
    }
78
}
79