Completed
Push — master ( 825d81...9c7056 )
by Maxime
08:49
created

ValidatedScope::extend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 6
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Distilleries\Contentful\Models\Scopes;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Scope;
8
use Illuminate\Database\Eloquent\Builder;
9
10 View Code Duplication
class ValidatedScope implements Scope
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * Apply the scope to a given Eloquent query builder.
14
     *
15
     * @param  \Illuminate\Database\Eloquent\Builder $builder
16
     * @param  \Illuminate\Database\Eloquent\Model $model
17
     * @return void
18
     */
19
    public function apply(Builder $builder, Model $model)
20
    {
21
        $builder
22
            ->where(function ($query) use ($model) {
23
                $query
24
                    ->whereNull($model->getTable() . '.validated_at')
25
                    ->orWhere($model->getTable() . '.validated_at','>=',Carbon::now()->format('Y-m-d H:i:s'));
26
            });
27
28
29
        $this->extend($builder);
30
    }
31
32
    /**
33
     * Extend Builder with following macros.
34
     *
35
     * @param  \Illuminate\Database\Eloquent\Builder $builder
36
     * @return void
37
     */
38
    public function extend(Builder $builder)
39
    {
40
        $builder->macro('withoutValidated', function (Builder $builder) {
41
            return $builder->withoutGlobalScope($this);
42
        });
43
    }
44
}
45