Completed
Push — master ( 419843...f5da21 )
by Anton
14s
created

Acl::isAllowed()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
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\Acl;
12
13
use Bluz\Common\Options;
14
use Bluz\Proxy\Auth;
15
16
/**
17
 * Acl
18
 *
19
 * @package  Bluz\Acl
20
 * @author   Anton Shevchuk
21
 * @link     https://github.com/bluzphp/framework/wiki/Acl
22
 */
23
class Acl
24
{
25
    use Options;
26
27
    /**
28
     * Check user access by pair module-privilege
29
     *
30
     * @param  string $module
31
     * @param  string $privilege
32
     *
33
     * @return bool
34
     */
35 18
    public function isAllowed($module, $privilege): bool
36
    {
37 18
        if ($privilege) {
38 5
            $user = Auth::getIdentity();
39 5
            return $user && $user->hasPrivilege($module, $privilege);
40
        }
41 13
        return true;
42
    }
43
}
44