Completed
Push — master ( 9a5869...5ef121 )
by Andrii
04:09
created

User::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
/*
4
 * HiPanel core package
5
 *
6
 * @link      https://hipanel.com/
7
 * @package   hipanel-core
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\components;
13
14
use yii\base\InvalidCallException;
15
use yii\base\InvalidConfigException;
16
17
class User extends \yii\web\User
18
{
19
    /**
20
     * @var string the seller login
21
     */
22
    public $seller;
23
24
    public function init()
25
    {
26
        parent::init();
27
        if (empty($this->seller)) {
28
            throw new InvalidConfigException('User "seller" must be set');
29
        }
30
    }
31
32
    public function not($key)
33
    {
34
        $identity = $this->getIdentity();
35
        if (!$identity) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $identity of type null|boolean is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
36
            throw new InvalidCallException();
37
        }
38
39
        return $identity->not($key);
0 ignored issues
show
Bug introduced by
The method not cannot be called on $identity (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
40
    }
41
42
    public function is($key)
43
    {
44
        $identity = $this->getIdentity();
45
        if (!$identity) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $identity of type null|boolean is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
46
            throw new InvalidCallException();
47
        }
48
49
        return $identity->is($key);
0 ignored issues
show
Bug introduced by
The method is cannot be called on $identity (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
50
    }
51
    /**
52
     * @inheritdoc
53
     * XXX fixes redirect loop when identity is set but the object is empty
54
     * @return bool
55
     */
56
    public function getIsGuest()
57
    {
58
        return empty($this->getIdentity()->id);
59
    }
60
}
61