Ticket   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 3
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getProxiesAttribute() 0 4 1
A setProxiesAttribute() 0 8 2
A isExpired() 0 4 1
A service() 0 4 1
A user() 0 4 1
A isProxy() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: chenyihong
5
 * Date: 16/8/1
6
 * Time: 14:53
7
 */
8
9
namespace Leo108\CAS\Models;
10
11
use Carbon\Carbon;
12
use Illuminate\Database\Eloquent\Model;
13
use Leo108\CAS\Contracts\Models\UserModel;
14
15
/**
16
 * Class Ticket
17
 * @package Leo108\CAS\Models
18
 *
19
 * @property integer   $id
20
 * @property string    $ticket
21
 * @property string    $service_url
22
 * @property integer   $service_id
23
 * @property integer   $user_id
24
 * @property array     $proxies
25
 * @property Carbon    $created_at
26
 * @property Carbon    $expire_at
27
 * @property UserModel $user
28
 * @property Service   $service
29
 */
30
class Ticket extends Model
31
{
32
    protected $table = 'cas_tickets';
33
    public $timestamps = false;
34
    protected $fillable = ['ticket', 'service_url', 'proxies', 'expire_at', 'created_at'];
35
    protected $casts = [
36
        'expire_at'  => 'datetime',
37
        'created_at' => 'datetime',
38
    ];
39
40
    public function getProxiesAttribute()
41
    {
42
        return json_decode($this->attributes['proxies'], true);
43
    }
44
45
    public function setProxiesAttribute($value)
46
    {
47
        //can not modify an existing record
48
        if ($this->id) {
49
            return;
50
        }
51
        $this->attributes['proxies'] = json_encode($value);
52
    }
53
54
    public function isExpired()
55
    {
56
        return $this->expire_at->getTimestamp() < time();
57
    }
58
59
    public function service()
60
    {
61
        return $this->belongsTo(Service::class);
62
    }
63
64
    public function user()
65
    {
66
        return $this->belongsTo(config('cas.user_table.model'), 'user_id', config('cas.user_table.id'));
67
    }
68
69
    public function isProxy()
70
    {
71
        return !empty($this->proxies);
72
    }
73
}
74