CommentScopes   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 3
Metric Value
eloc 8
c 3
b 0
f 3
dl 0
loc 35
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeMostLiked() 0 3 1
A scopeNewest() 0 3 1
A scopeApproved() 0 3 1
A scopeParent() 0 3 1
A scopeOldest() 0 3 1
A scopePending() 0 3 1
A scopeMostReplied() 0 3 1
1
<?php
2
3
namespace Usamamuneerchaudhary\Commentify\Scopes;
4
5
use Illuminate\Database\Eloquent\Builder;
6
7
trait CommentScopes
8
{
9
    public function scopeParent(Builder $builder): void
10
    {
11
        $builder->whereNull('parent_id');
12
    }
13
14
    public function scopeNewest(Builder $builder): Builder
15
    {
16
        return $builder->latest();
17
    }
18
19
    public function scopeOldest(Builder $builder): Builder
20
    {
21
        return $builder->oldest();
22
    }
23
24
    public function scopeMostLiked(Builder $builder): Builder
25
    {
26
        return $builder->orderBy('likes_count', 'desc');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $builder->orderBy('likes_count', 'desc') could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
27
    }
28
29
    public function scopeMostReplied(Builder $builder): Builder
30
    {
31
        return $builder->orderBy('children_count', 'desc');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $builder->orderBy...hildren_count', 'desc') could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
32
    }
33
34
    public function scopeApproved(Builder $builder): Builder
35
    {
36
        return $builder->where('is_approved', true);
37
    }
38
39
    public function scopePending(Builder $builder): Builder
40
    {
41
        return $builder->where('is_approved', false);
42
    }
43
}
44