Completed
Push — master ( 5c8f9b...c72a1f )
by Christopher
01:11
created

Comment   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A commentable() 0 4 1
A approve() 0 6 1
A disapprove() 0 6 1
A newEloquentBuilder() 0 4 1
1
<?php
2
3
namespace Chriscreates\Blog;
4
5
use Chriscreates\Blog\Builders\CommentBuilder;
6
use Chriscreates\Blog\Traits\Comment\CommentApproval;
7
use Chriscreates\Blog\Traits\IsAuthorable;
8
use Illuminate\Database\Eloquent\Model;
9
10
class Comment extends Model
11
{
12
    use CommentApproval,
13
    IsAuthorable;
14
15
    protected $table = 'comments';
16
17
    protected $primaryKey = 'id';
18
19
    public $guarded = ['id'];
20
21
    public $timestamps = true;
22
23
    protected $casts = [
24
        'is_approved' => 'boolean',
25
    ];
26
27
    public function commentable()
28
    {
29
        return $this->morphTo();
30
    }
31
32
    public function approve()
33
    {
34
        $this->update(['is_approved' => true]);
35
36
        return $this;
37
    }
38
39
    public function disapprove()
40
    {
41
        $this->update(['is_approved' => false]);
42
43
        return $this;
44
    }
45
46
    public function newEloquentBuilder($query) : CommentBuilder
47
    {
48
        return new CommentBuilder($query);
49
    }
50
}
51