Completed
Pull Request — master (#383)
by
unknown
01:20
created

FilterTrashed   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 3
1
<?php
2
3
namespace Spatie\QueryBuilder\Filters;
4
5
use Illuminate\Database\Eloquent\Builder;
6
7
/**
8
 * FilterTrashed provides filter for soft deleted (trashed) records.
9
 *
10
 * This filter responds to particular values:
11
 *
12
 * - 'with' - include 'trashed' records to the result set.
13
 * - 'only' - return only 'trashed' records at the result set.
14
 * - any other - return only records without 'trashed' at the result set.
15
 *
16
 * @see \Illuminate\Database\Eloquent\SoftDeletes
17
 * @see \Spatie\QueryBuilder\AllowedFilter::trashed()
18
 */
19
class FilterTrashed implements Filter
20
{
21
    /** {@inheritdoc} */
22
    public function __invoke(Builder $query, $value, string $property)
23
    {
24
        if ($value === 'with') {
25
            $query->withTrashed();
26
27
            return;
28
        }
29
30
        if ($value === 'only') {
31
            $query->onlyTrashed();
32
33
            return;
34
        }
35
36
        $query->withoutTrashed();
37
    }
38
}
39