Completed
Push — master ( 15085c...c17da1 )
by vistart
04:03
created

User::getIsWebmaster()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\user\components;
14
15
use rhosocial\user\rbac\roles\Admin;
16
use rhosocial\user\rbac\roles\Webmaster;
17
use yii\base\Event;
18
19
/**
20
 * Class User
21
 * @package rhosocial\user\web\components
22
 * @version 1.0
23
 * @author vistart <[email protected]>
24
 */
25
class User extends \rhosocial\base\models\web\User
26
{
27
    public function init()
28
    {
29
        parent::init();
30
        $this->on(static::EVENT_AFTER_LOGIN, [$this, 'onRecordLogin']);
31
    }
32
33
    /**
34
     * @param Event $event
35
     */
36
    public function onRecordLogin($event)
37
    {
38
        return $event->sender->identity->recordLogin();
39
    }
40
41
    /**
42
     * @return bool|mixed
43
     */
44
    public function getIsAdmin()
45
    {
46
        if ($this->getIsGuest()) {
47
            return false;
48
        }
49
        return $this->can((new Admin)->name, $this->identity);
0 ignored issues
show
Documentation introduced by
$this->identity is of type object<yii\web\IdentityInterface>|null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
    }
51
52
    /**
53
     * @return bool|mixed
54
     */
55
    public function getIsWebmaster()
56
    {
57
        if ($this->getIsGuest()) {
58
            return false;
59
        }
60
        return $this->can((new Webmaster)->name, $this->identity);
0 ignored issues
show
Documentation introduced by
$this->identity is of type object<yii\web\IdentityInterface>|null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
    }
62
63
    /**
64
     *
65
     */
66
    public function getLoginPriority()
67
    {
68
        return [
69
            'id' => \rhosocial\user\User::$idRegex,
70
            'username' => \rhosocial\user\User::$usernameRegex,
71
        ];
72
    }
73
}
74