Code Duplication    Length = 31-35 lines in 2 locations

src/Distilleries/Contentful/Models/Scopes/NotNullSlugScope.php 1 location

@@ 9-39 (lines=31) @@
6
use Illuminate\Database\Eloquent\Scope;
7
use Illuminate\Database\Eloquent\Builder;
8
9
class NotNullSlugScope implements Scope
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

src/Distilleries/Contentful/Models/Scopes/ValidatedScope.php 1 location

@@ 10-44 (lines=35) @@
7
use Illuminate\Database\Eloquent\Scope;
8
use Illuminate\Database\Eloquent\Builder;
9
10
class ValidatedScope implements Scope
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