Comment   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 12
dl 0
loc 65
rs 10
c 2
b 0
f 1
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 0 3 1
A children() 0 3 1
A presenter() 0 3 1
A newFactory() 0 3 1
A commentable() 0 3 1
A isParent() 0 3 1
1
<?php
2
3
namespace Usamamuneerchaudhary\Commentify\Models;
4
5
use Illuminate\Database\Eloquent\Factories\HasFactory;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8
use Illuminate\Database\Eloquent\Relations\HasMany;
9
use Illuminate\Database\Eloquent\Relations\MorphTo;
10
use Illuminate\Database\Eloquent\SoftDeletes;
11
use Usamamuneerchaudhary\Commentify\Database\Factories\CommentFactory;
12
use Usamamuneerchaudhary\Commentify\Models\Presenters\CommentPresenter;
13
use Usamamuneerchaudhary\Commentify\Scopes\CommentScopes;
14
use Usamamuneerchaudhary\Commentify\Scopes\HasLikes;
15
16
class Comment extends Model
17
{
18
19
    use CommentScopes, SoftDeletes, HasFactory, HasLikes;
0 ignored issues
show
Bug introduced by
The trait Illuminate\Database\Eloquent\Factories\HasFactory requires the property $factoryClass which is not provided by Usamamuneerchaudhary\Commentify\Models\Comment.
Loading history...
20
21
    /**
22
     * @var string
23
     */
24
    protected $table = 'comments';
25
26
    /**
27
     * @var string[]
28
     */
29
    protected $fillable = ['body'];
30
31
    protected $withCount = [
32
        'likes',
33
    ];
34
35
    /**
36
     * @return CommentPresenter
37
     */
38
    public function presenter(): CommentPresenter
39
    {
40
        return new CommentPresenter($this);
41
    }
42
43
    /**
44
     * @return bool
45
     */
46
    public function isParent(): bool
47
    {
48
        return is_null($this->parent_id);
0 ignored issues
show
Bug introduced by
The property parent_id does not seem to exist on Usamamuneerchaudhary\Commentify\Models\Comment. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
49
    }
50
51
    /**
52
     * @return BelongsTo
53
     */
54
    public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
55
    {
56
        return $this->belongsTo(User::class);
57
    }
58
59
    /**
60
     * @return HasMany
61
     */
62
    public function children(): \Illuminate\Database\Eloquent\Relations\HasMany
63
    {
64
        return $this->hasMany(Comment::class, 'parent_id')->oldest();
65
    }
66
67
    /**
68
     * @return MorphTo
69
     */
70
    public function commentable(): \Illuminate\Database\Eloquent\Relations\MorphTo
71
    {
72
        return $this->morphTo();
73
    }
74
75
    /**
76
     * @return CommentFactory
77
     */
78
    protected static function newFactory(): CommentFactory
79
    {
80
        return CommentFactory::new();
81
    }
82
}
83