Passed
Push — main ( 843490...c1da4d )
by Mohammad
07:53
created

SoftDeletesRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withTrash() 0 5 1
A restore() 0 3 1
A onlyTrash() 0 5 1
A forceDelete() 0 3 1
1
<?php
2
3
use Illuminate\Database\Eloquent\Builder;
4
5
trait SoftDeletesRepository
6
{
7
    /**
8
     * @param int $id
9
     *
10
     * @return bool
11
     */
12
    public function restore(int $id): bool
13
    {
14
        return $this->getNewBuilderWithScope()->where('id', $id)->restore();
0 ignored issues
show
Bug introduced by
It seems like getNewBuilderWithScope() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
        return $this->/** @scrutinizer ignore-call */ getNewBuilderWithScope()->where('id', $id)->restore();
Loading history...
15
    }
16
17
    /**
18
     * @param int $id
19
     *
20
     * @return bool
21
     */
22
    public function forceDelete(int $id): bool
23
    {
24
        return $this->getNewBuilderWithScope()->where('id', $id)->forceDelete();
25
    }
26
27
    public function onlyTrash(): self
28
    {
29
        $this->scope(fn (Builder $builder) => $builder->onlyTrash());
0 ignored issues
show
Bug introduced by
It seems like scope() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $this->/** @scrutinizer ignore-call */ 
30
               scope(fn (Builder $builder) => $builder->onlyTrash());
Loading history...
30
31
        return $this;
32
    }
33
34
    public function withTrash(): self
35
    {
36
        $this->scope(fn (Builder $builder) => $builder->withTrash());
37
38
        return $this;
39
    }
40
}
41