Completed
Push — master ( 586621...d825f0 )
by Andrii
03:32
created

User::getIsGuest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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\InvalidConfigException;
15
16
class User extends \yii\web\User
17
{
18
    /**
19
     * @var string the seller login
20
     */
21
    public $seller;
22
23
    public function not($key)
24
    {
25
        $identity = $this->getIdentity();
26
        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...
27
            throw new InvalidConfigException();
28
        }
29
30
        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...
31
    }
32
33
    public function is($key)
34
    {
35
        $identity = $this->getIdentity();
36
        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...
37
            throw new InvalidConfigException();
38
        }
39
40
        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...
41
    }
42
    /**
43
     * @inheritdoc
44
     * XXX fixes redirect loop when identity is set but the object is empty
45
     * @return bool
46
     */
47
    public function getIsGuest()
48
    {
49
        return empty($this->getIdentity()->id);
50
    }
51
}
52