Passed
Push — main ( 69451c...874877 )
by Garbuz
03:25
created

GlobalToken   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 20
dl 0
loc 59
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0

1 Method

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