LastVisitBehavior   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 7
c 1
b 0
f 1
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A afterAction() 0 9 2
A events() 0 4 1
1
<?php
2
3
namespace modules\users\behavior;
4
5
use Yii;
6
use yii\base\Behavior;
7
use yii\console\Controller;
8
9
/**
10
 * Class LastVisitBehavior
11
 * @package modules\users\behavior
12
 */
13
class LastVisitBehavior extends Behavior
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function events()
19
    {
20
        return [
21
            Controller::EVENT_AFTER_ACTION => 'afterAction'
22
        ];
23
    }
24
25
    /**
26
     * @return bool
27
     */
28
    public function afterAction()
29
    {
30
        if (!Yii::$app->user->isGuest) {
31
            /** @var \yii\web\IdentityInterface $model */
32
            $model = Yii::$app->user->identity;
33
            /** @var \yii\behaviors\TimestampBehavior $model Updates a timestamp attribute to the current timestamp. */
34
            $model->touch('last_visit');
35
        }
36
        return true;
37
    }
38
}
39