User   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 37
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 8 3
A can() 0 7 3
1
<?php
2
3
namespace app\components;
4
5
class User extends \yii\web\User
6
{
7 93
    public function init()
8
    {
9 93
        parent::init();
10
11 93
        if (!$this->getIsGuest() && !$this->getIdentity()->isActive()) {
12 1
            $this->logout();
13
        }
14 93
    }
15
16
    /**
17
     * Checks if the user can perform the operation as specified by the given permission.
18
     *
19
     * Note that you must configure "authManager" application component in order to use this method.
20
     * Otherwise an exception will be thrown.
21
     *
22
     * @param string $permissionName the name of the permission (e.g. "edit post") that needs access check.
23
     * @param array $params name-value pairs that would be passed to the rules associated
24
     * with the roles and permissions assigned to the user. A param with name 'user' is added to
25
     * this array, which holds the value of [[id]].
26
     * @param boolean $allowCaching whether to allow caching the result of access check.
27
     * When this parameter is true (default), if the access check of an operation was performed
28
     * before, its result will be directly returned when calling this method to check the same
29
     * operation. If this parameter is false, this method will always call
30
     * [[\yii\rbac\ManagerInterface::checkAccess()]] to obtain the up-to-date access result. Note that this
31
     * caching is effective only within the same request and only works when `$params = []`.
32
     * @return boolean whether the user can perform the operation as specified by the given permission.
33
     */
34 25
    public function can($permissionName, $params = [], $allowCaching = true)
35
    {
36 25
        if (!$this->getIsGuest() && $this->getIdentity()->isSuperUser()) {
37 13
            return true;
38
        }
39 14
        return parent::can($permissionName, $params, $allowCaching);
40
    }
41
}
42