Completed
Pull Request — master (#399)
by Anton
04:06
created

Acl   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A isAllowed() 0 10 4
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
    public function isAllowed($module, $privilege) : bool
36
    {
37
        if ($privilege) {
38
            $user = Auth::getIdentity();
39
            if (!$user || !$user->hasPrivilege($module, $privilege)) {
40
                return false;
41
            }
42
        }
43
        return true;
44
    }
45
}
46