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

AuthManager::checkAccess()   B

Complexity

Conditions 7
Paths 18

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 26.3215

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 4
cts 15
cp 0.2667
rs 8.2222
cc 7
eloc 11
nc 18
nop 3
crap 26.3215
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