Completed
Push — master ( 6ff6d1...70482c )
by Alexey
02:17
created

LogoutAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 28
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 10 1
A trigger() 0 5 1
1
<?php
2
3
namespace yiicod\auth\actions\webUser;
4
5
use Yii;
6
use yii\base\Action;
7
use yii\base\Event;
8
use yiicod\auth\actions\ActionEvent;
9
10
/**
11
 * Login action
12
 * @author Orlov Alexey <[email protected]>
13
 */
14
class LogoutAction extends Action
15
{
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
        $this->trigger(static::EVENT_BEFORE_LOGOUT, new ActionEvent($this));
28
29
        Yii::$app->user->logout();
30
31
        $this->trigger(static::EVENT_AFTER_LOGOUT, new ActionEvent($this));
32
33
        return Yii::$app->controller->goHome();
34
    }
35
36
    public function trigger($name, Event $event = null)
37
    {
38
        Yii::$app->trigger(sprintf('yiicod.auth.actions.webUser.LogoutAction.%s', $name), $event);
39
        return parent::trigger($name, $event);
40
    }
41
}
42