Topic   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 0 Features 2
Metric Value
dl 0
loc 88
rs 10
c 5
b 0
f 2
wmc 8
lcom 1
cbo 3

8 Methods

Rating   Name   Duplication   Size   Complexity  
A favoriteBy() 0 4 1
A attentionBy() 0 4 1
A node() 0 4 1
A lastReplyUser() 0 4 1
A replies() 0 4 1
A user() 0 4 1
A votes() 0 4 1
A getPresenterClass() 0 4 1
1
<?php
2
3
namespace PHPHub;
4
5
use Illuminate\Database\Eloquent\SoftDeletes;
6
use McCool\LaravelAutoPresenter\HasPresenter;
7
use PHPHub\Presenters\TopicPresenter;
8
use Illuminate\Database\Eloquent\Model;
9
10
class Topic extends Model implements HasPresenter
11
{
12
    use SoftDeletes;
13
14
    public static $includable = [
15
        'id',
16
        'title',
17
        'body',
18
        'user_id',
19
        'node_id',
20
        'is_excellent',
21
        'is_wiki',
22
        'is_blocked',
23
        'reply_count',
24
        'view_count',
25
        'favorite_count',
26
        'vote_count',
27
        'last_reply_user_id',
28
        'created_at',
29
        'updated_at',
30
        'body_original',
31
        'excerpt',
32
    ];
33
34
    protected $fillable = ['body', 'title', 'node_id', 'user_id'];
35
36
    protected $morphClass = 'Topic';
37
38
    protected $casts = [
39
        'id'                 => 'int',
40
        'user_id'            => 'int',
41
        'node_id'            => 'int',
42
        'last_reply_user_id' => 'int',
43
        'favorite_count'     => 'int',
44
        'view_count'         => 'int',
45
        'reply_count'        => 'int',
46
        'vote_count'         => 'int',
47
        'notification_count' => 'int',
48
        'is_excellent'       => 'boolean',
49
        'is_wiki'            => 'boolean',
50
        'is_blocked'         => 'boolean',
51
    ];
52
53
    public function user()
54
    {
55
        return $this->belongsTo(User::class);
56
    }
57
58
    public function votes()
59
    {
60
        return $this->morphMany(Vote::class, 'votable');
61
    }
62
63
    public function node()
64
    {
65
        return $this->belongsTo(Node::class);
66
    }
67
68
    public function lastReplyUser()
69
    {
70
        return $this->belongsTo(User::class, 'last_reply_user_id');
71
    }
72
73
    public function replies()
74
    {
75
        return $this->hasMany(Reply::class);
76
    }
77
78
    public function favoriteBy()
79
    {
80
        return $this->belongsToMany(User::class, 'favorites')->withTimestamps();
81
    }
82
83
    public function attentionBy()
84
    {
85
        return $this->belongsToMany(User::class, 'attentions')->withTimestamps();
86
    }
87
88
    /**
89
     * Get the presenter class.
90
     *
91
     * @return string
92
     */
93
    public function getPresenterClass()
94
    {
95
        return TopicPresenter::class;
96
    }
97
}
98