Completed
Pull Request — master (#413)
by Anton
06:02
created

Acl   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 80%

Importance

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

1 Method

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