GlobalToken::isValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Garbuzivan\Laraveltokens\Models;
6
7
use Carbon\Carbon;
8
use Garbuzivan\Laraveltokens\Interfaces\ModelToken;
9
use Illuminate\Database\Eloquent\Factories\HasFactory;
10
use Illuminate\Database\Eloquent\Model;
11
12
class GlobalToken extends Model implements ModelToken
13
{
14
    use HasFactory;
15
16
    protected $table = 'global_tokens';
17
18
    /**
19
     * @var string[]
20
     */
21
    protected $fillable = [
22
        'token',
23
        'title',
24
        'expiration',
25
        'last_use',
26
    ];
27
28
    /**
29
     * @var string[]
30
     */
31
    protected $dates = [
32
        'expiration',
33
        'last_use',
34
        'created_at',
35
        'updated_at',
36
    ];
37
38
    /**
39
     * The attributes that should be hidden for arrays.
40
     *
41
     * @var array
42
     */
43
    protected $hidden = [];
44
45
    /**
46
     * The attributes that should be casted to native types.
47
     *
48
     * @var array
49
     */
50
    protected $casts = [
51
        'id' => 'integer',
52
        'token' => 'string',
53
        'title' => 'string',
54
        'expiration' => 'datetime',
55
        'last_use' => 'datetime',
56
    ];
57
58
    /**
59
     * Validation rules
60
     *
61
     * @var array
62
     */
63
    public static array $rules = [
64
        'token' => 'required',
65
    ];
66
67
    /**
68
     * Проверка валидности токена по дате
69
     * @return bool
70
     */
71
    public function isValid(): bool
72
    {
73
        return is_null($this->expiration) || $this->expiration > Carbon::now();
74
    }
75
}
76