Completed
Push — master ( 2e8683...7e20fc )
by Igor
07:20
created

User::init()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 0
crap 3.072
1
<?php
2
3
namespace app\components;
4
5
class User extends \yii\web\User
6
{
7 147
    public function init()
8
    {
9 147
        parent::init();
10
11 147
        if (!$this->getIsGuest() && !$this->getIdentity()->isActive()) {
12
            $this->logout();
13
        }
14 147
    }
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
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
34
     */
35 66
    public function can($permissionName, $params = [], $allowCaching = true)
36
    {
37 66
        if (!$this->getIsGuest() && $this->getIdentity()->isSuperUser()) {
38 52
            return true;
39
        }
40 63
        return parent::can($permissionName, $params, $allowCaching);
41
    }
42
}
43