Passed
Push — master ( f1a782...17ae54 )
by Ion
04:19 queued 45s
created

UserToken::getExpireOnAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace App\Models;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
8
/**
9
 * Class UserToken
10
 *
11
 * @property int $id
12
 * @property int $user_id
13
 * @property string $token
14
 * @property int $type
15
 * @property Carbon|null $expire_on
16
 * @property Carbon|null $created_at
17
 * @property Carbon|null $updated_at
18
 *
19
 * @property-read User $user
20
 *
21
 * @package App\Models
22
 */
23
class UserToken extends Model
24
{
25
    /** @var int */
26
    const TYPE_REMEMBER_ME = 1;
27
28
    /** @var bool */
29
    public $timestamps = true;
30
31
    /** @var string */
32
    protected $table = 'user_tokens';
33
34
    /** @var array */
35
    protected $fillable = [
36
        'user_id',
37
        'token',
38
        'type',
39
        'expire_on'
40
    ];
41
42
    /** @var array */
43
    protected $casts = [
44
        'type' => 'int'
45
    ];
46
47
    /**
48
     * User.
49
     *
50
     * @return BelongsTo
51
     */
52
    public function user()
53
    {
54
        return $this->belongsTo(User::class, 'user_id', 'id');
55
    }
56
57
    /**
58
     * @param $value
59
     *
60
     * @return Carbon
61
     */
62
    public function getExpireOnAttribute($value)
63
    {
64
        if ($value !== null) {
65
            return Carbon::parse($value);
66
        }
67
68
        return null;
69
    }
70
}
71