Completed
Push — master ( 467d47...6f2bb4 )
by Anton
14s
created

AbstractIdentity::hasPrivilege()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 6
ccs 0
cts 3
cp 0
c 0
b 0
f 0
cc 1
eloc 3
nop 2
crap 2
rs 9.4285
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Auth;
12
13
use Bluz\Db\Row;
14
15
/**
16
 * Abstract class for Users\Row
17
 *
18
 * @package Bluz\Auth
19
 *
20
 * @property integer $id
21
 * @property string  $login
22
 * @property string  $email
23
 */
24
abstract class AbstractIdentity extends Row implements IdentityInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    abstract public function getPrivileges() : array;
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getId() : ?int
35
    {
36
        return $this->id ? (int)$this->id : null;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function hasPrivilege($module, $privilege) : bool
43
    {
44
        $privileges = $this->getPrivileges();
45
46
        return in_array("$module:$privilege", $privileges, true);
47
    }
48
}
49