BlogCommentApprovedAndDefaultOrderScope   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 5 1
1
<?php
2
3
namespace WebDevEtc\BlogEtc\Scopes;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Scope;
8
9
class BlogCommentApprovedAndDefaultOrderScope implements Scope
10
{
11
    /**
12
     * By default only show approved blog comments.
13
     * Order by id, asc - which is what we would always want when showing comments.
14
     * We do not support comment threads/replies.
15
     *
16
     * In the admin panel we disable this scope with ::withoutGlobalScopes() or ::withoutGlobalScope(...)
17
     */
18
    public function apply(Builder $builder, Model $model)
19
    {
20
        $builder->orderBy('id', 'asc');
21
        $builder->limit(config('blogetc.comments.max_num_of_comments_to_show', 500));
22
        $builder->where('approved', true);
23
    }
24
}
25