Passed
Push — main ( 17b0d5...88cc6f )
by Usama
04:11
created

CommentScopes::scopePending()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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