Passed
Push — dev_2x ( f00e1a...d7ecbe )
by Adrian
01:35
created

SoftDeleteTrait::withTrashed()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 11
rs 10
cc 3
nc 3
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Query;
5
6
trait SoftDeleteTrait
7
{
8
    public function withTrashed()
9
    {
10
        $guards = [];
11
        foreach ($this->guards as $k => $v) {
12
            if ($v != $this->deletedAtColumn . ' IS NULL') {
13
                $guards[$k] = $v;
14
            }
15
        }
16
        $this->guards = $guards;
0 ignored issues
show
Bug Best Practice introduced by
The property guards does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17
18
        return $this;
19
    }
20
21
    public function withoutTrashed()
22
    {
23
        $guards = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $guards is dead and can be removed.
Loading history...
24
        $hasGuard = false;
25
        foreach ($this->guards as $k => $v) {
26
            if ($v === $this->deletedAtColumn . ' IS NULL') {
27
                $hasGuard = true;
28
                break;
29
            }
30
        }
31
32
        if (!$hasGuard) {
33
            $this->guards[] = $this->deletedAtColumn . ' IS NULL';
0 ignored issues
show
Bug Best Practice introduced by
The property guards does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
34
        }
35
36
        return $this;
37
    }
38
39
    public function onlyTrashed()
40
    {
41
        $this->withTrashed();
42
        $this->guards[] = $this->deletedAtColumn . ' IS NOT NULL';
0 ignored issues
show
Bug Best Practice introduced by
The property guards does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
44
        return $this;
45
    }
46
}
47