Completed
Push — master ( 580028...d7e9e8 )
by Charles
02:19
created

ActiveRecord   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A afterFind() 0 9 2
A isExpired() 0 15 3
1
<?php
2
3
namespace yrc\redis;
4
5
use yii\redis\ActiveRecord as YiiRedisActiveRecord;
6
use Yii;
7
8
abstract class ActiveRecord extends YiiRedisActiveRecord
9
{
10
    /**
11
     * After find reconstitute the keypairs
12
     */
13
    public function afterFind()
14
    {
15
        // If the object is expired, delete it
16
        if ($this->isExpired()) {
17
            throw new \yii\base\Exception(Yii::t('yrc', 'Element has expired.'));
18
        }
19
        
20
        return parent::afterFind();
21
    }
22
23
    /**
24
     * Return true if the token is expired
25
     * @return boolean
26
     */
27
    public function isExpired()
28
    {
29
        if (empty($this->expires_at)) {
30
            return false;
31
        }
32
        
33
        // Handle token expiration by actually deleting the token
34
        if ($this->expires_at < time()) {
35
            $this->delete();
36
37
            return true;
38
        }
39
40
        return false;
41
    }
42
}