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

NotNullSlugScope::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 Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Scope;
7
use Illuminate\Database\Eloquent\Builder;
8
9 View Code Duplication
class NotNullSlugScope 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...
10
{
11
    /**
12
     * Apply the scope to a given Eloquent query builder.
13
     *
14
     * @param  \Illuminate\Database\Eloquent\Builder  $builder
15
     * @param  \Illuminate\Database\Eloquent\Model  $model
16
     * @return void
17
     */
18
    public function apply(Builder $builder, Model $model)
19
    {
20
        $builder
21
            ->whereNotNull($model->getTable() . '.slug')
22
            ->where($model->getTable() . '.slug', '!=', '');
23
24
        $this->extend($builder);
25
    }
26
27
    /**
28
     * Extend Builder with following macros.
29
     *
30
     * @param  \Illuminate\Database\Eloquent\Builder  $builder
31
     * @return void
32
     */
33
    public function extend(Builder $builder)
34
    {
35
        $builder->macro('allowNullSlug', function (Builder $builder) {
36
            return $builder->withoutGlobalScope($this);
37
        });
38
    }
39
}
40