Passed
Push — master ( ab2678...bf154d )
by webdevetc
14:17
created

BlogEtcPublishedScope   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 2
eloc 5
dl 0
loc 13
rs 10
c 5
b 1
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 8 2
1
<?php
2
3
namespace WebDevEtc\BlogEtc\Scopes;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Scope;
9
use WebDevEtc\BlogEtc\Helpers;
10
11
class BlogEtcPublishedScope implements Scope
12
{
13
    /**
14
     * Only show posts which are published in the past, unless the user has admin access.
15
     */
16
    public function apply(Builder $builder, Model $model)
17
    {
18
        if (Helpers::hasAdminGateAccess()) {
19
            return;
20
        }
21
22
        $builder->where('is_published', true);
23
        $builder->where('posted_at', '<=', Carbon::now());
24
    }
25
}
26