Completed
Push — master ( 19e1c8...a74d0d )
by Christopher
01:06
created

CommentScopes   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeLatest() 0 4 1
A scopeLastMonth() 0 6 1
A scopeLastWeek() 0 6 1
A scopeApproved() 0 4 1
A scopeUnapproved() 0 4 1
1
<?php
2
3
namespace Chriscreates\Blog\Traits\Comment;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Builder;
7
8
trait CommentScopes
9
{
10
    public function scopeLatest(Builder $query)
11
    {
12
        return $query->orderBy('created_at', 'DESC');
0 ignored issues
show
Bug introduced by
The method orderBy() does not exist on Illuminate\Database\Eloquent\Builder. Did you maybe mean enforceOrderBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
13
    }
14
15
    public function scopeLastMonth(Builder $query)
16
    {
17
        return $query->whereBetween('created_at', [
18
            Carbon::now()->subMonth(), Carbon::now(),
19
        ])->latest();
20
    }
21
22
    public function scopeLastWeek(Builder $query)
23
    {
24
        return $query->whereBetween('created_at', [
25
            Carbon::now()->subWeek(), Carbon::now(),
26
        ])->latest();
27
    }
28
29
    public function scopeApproved($query)
30
    {
31
        return $query->where('is_approved', true);
32
    }
33
34
    public function scopeUnapproved($query)
35
    {
36
        return $query->where('is_approved', false);
37
    }
38
}
39