Completed
Pull Request — master (#1)
by Andrii
05:21
created

AuthManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 26.32%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 43
ccs 5
cts 19
cp 0.2632
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A saveAssignments() 0 3 1
B checkAccess() 0 17 6
A persistAssignments() 0 4 1
1
<?php
2
3
/*
4
 * RBAC implementation for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-rbac
7
 * @package   hipanel-rbac
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\rbac;
13
14
use Yii;
15
16
/**
17
 * HiPanel AuthManager.
18
 *
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class AuthManager extends \yii\rbac\PhpManager
22
{
23
    public $itemFile       = '@hipanel/rbac/files/items.php';
24
    public $ruleFile       = '@hipanel/rbac/files/rules.php';
25
    public $assignmentFile = '@hipanel/rbac/files/assignments.php';
26
27
    use SetterTrait;
28
29
    /**
30
     * We don't keep all the assignments, only persistent.
31
     * @see persistAssignments
32
     */
33 10
    protected function saveAssignments()
34
    {
35 10
    }
36
37
    /**
38
     * Does real assignments saving.
39
     * The idea is to split persistent assignments from session only.
40
     */
41
    public function persistAssignments()
42
    {
43
        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...
44
    }
45
46 10
    public function checkAccess($userId, $permission, $params = [])
47
    {
48 10
        if (isset(Yii::$app->user)) {
49
            $user = Yii::$app->user->identity;
50
            if (!$user || $user->id != $userId) {
51
                $user = call_user_func([Yii::$app->user->identityClass, 'findIdentity'], $userId);
52
            }
53
            if (isset($user->username)) {
54
                $userId = $user->username;
55
            }
56
            if (isset($user->roles)) {
57
                $this->setAssignments($user->roles, $userId);
58
            }
59
        }
60
61 10
        return parent::checkAccess($userId, $permission, $params);
62
    }
63
}
64