AbstractIdentity::hasPrivilege()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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