Completed
Push — master ( 44a76b...721920 )
by Dmitry
01:51
created

AuthManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 30%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 44
ccs 6
cts 20
cp 0.3
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A saveAssignments() 0 3 1
A persistAssignments() 0 4 1
B checkAccess() 0 18 7
1
<?php
2
/**
3
 * RBAC implementation for HiPanel.
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-rbac
6
 * @package   hipanel-rbac
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\rbac;
12
13
use Yii;
14
15
/**
16
 * HiPanel AuthManager.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class AuthManager extends \yii\rbac\PhpManager
21
{
22
    public $itemFile       = '@hipanel/rbac/files/items.php';
23
    public $ruleFile       = '@hipanel/rbac/files/rules.php';
24
    public $assignmentFile = '@hipanel/rbac/files/assignments.php';
25
26
    use SetterTrait;
27
28
    /**
29
     * We don't keep all the assignments, only persistent.
30
     * @see persistAssignments
31
     */
32 14
    protected function saveAssignments()
33
    {
34 14
    }
35
36
    /**
37
     * Does real assignments saving.
38
     * The idea is to split persistent assignments from session only.
39
     */
40
    public function persistAssignments()
41
    {
42
        parent::saveAssignments();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (saveAssignments() instead of persistAssignments()). Are you sure this is correct? If so, you might want to change this to $this->saveAssignments().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
43
    }
44
45 14
    public function checkAccess($userId, $permission, $params = [])
46
    {
47 14
        if (isset(Yii::$app->user)) {
48
            $user = Yii::$app->user->identity;
49
            if (!$user || $user->id !== $userId) {
50
                $user = call_user_func([Yii::$app->user->identityClass, 'findIdentity'], $userId);
51
            }
52
            if (isset($user->username)) {
53
                $userId = $user->username;
54
            }
55
            if (isset($user->roles)) {
56
                $this->setAssignments($user->roles, $userId);
57
            }
58
        }
59
60 14
        return parent::checkAccess($userId, $permission, $params)
61 14
            && !parent::checkAccess($userId, "deny:$permission", $params);
62
    }
63
}
64