LogoutAction::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace yiicod\auth\actions\webUser;
4
5
use Yii;
6
use yii\base\Action;
7
use yii\base\ActionEvent;
8
use yii\base\Event;
9
10
/**
11
 * Login action
12
 *
13
 * @author Orlov Alexey <[email protected]>
14
 */
15
class LogoutAction extends Action
16
{
17
    const EVENT_BEFORE_LOGOUT = 'beforeLogout';
18
    const EVENT_AFTER_LOGOUT = 'afterLogout';
19
20
    public $view = '';
21
22
    /**
23
     * Logs out the current user and redirect to homepage.
24
     */
25
    public function run()
26
    {
27
        Event::trigger(self::class, static::EVENT_BEFORE_LOGOUT, new ActionEvent($this, ['sender' => $this]));
28
29
        Yii::$app->user->logout();
30
31
        Event::trigger(self::class, static::EVENT_AFTER_LOGOUT, new ActionEvent($this, ['sender' => $this]));
32
33
        return $this->controller->goHome();
0 ignored issues
show
Bug introduced by
The method goHome does only exist in yii\web\Controller, but not in yii\base\Controller and yii\console\Controller.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
34
    }
35
}
36