LogoutAction   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 10 1
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