Invite::clean()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Apps\ActiveRecord;
4
5
use Ffcms\Core\Arch\ActiveModel;
6
use Ffcms\Core\Helper\Date;
7
8
/**
9
 * Class Invite. Active record model to store invite keys
10
 * @package Apps\ActiveRecord
11
 * @property int $id
12
 * @property string $token
13
 * @property string $email
14
 * @property string $created_at
15
 * @property string $updated_at
16
 */
17
class Invite extends ActiveModel
18
{
19
    const TOKEN_VALID_TIME = 604800; // 7 days
20
21
    protected $casts = [
22
        'id' => 'integer',
23
        'token' => 'string',
24
        'email' => 'string'
25
    ];
26
27
    /**
28
     * Cleanup old invites
29
     */
30
    public static function clean()
31
    {
32
        $date = time() - self::TOKEN_VALID_TIME;
33
        $timestamp = Date::convertToDatetime($date, Date::FORMAT_SQL_TIMESTAMP);
34
        self::where('created_at', '<=', $timestamp)->delete();
35
    }
36
}
37