GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ModelSoftDeleting::afterRestore()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace LaravelFlare\Flare\Admin\Models\Traits;
4
5
use LaravelFlare\Flare\Events\ModelDelete;
6
use LaravelFlare\Flare\Events\AfterDelete;
7
use LaravelFlare\Flare\Events\BeforeDelete;
8
use LaravelFlare\Flare\Events\ModelRestore;
9
use LaravelFlare\Flare\Events\AfterRestore;
10
use LaravelFlare\Flare\Events\BeforeRestore;
11
use LaravelFlare\Flare\Events\ModelSoftDelete;
12
13
trait ModelSoftDeleting
14
{
15
    use ModelDeleting;
16
17
    /**
18
     * Overrides the ModelQuerying provided method 
19
     * with one which searches withTrashed scope.
20
     * 
21
     * @param int $modelitemId
22
     * 
23
     * @return
24
     */
25
    public function find($modelitemId)
26
    {
27
        return $this->findWithTrashed($modelitemId);
28
    }
29
30
    /**
31
     * Finds model and includes withTrashed() scope in query.
32
     *
33
     * @param int $modelitemId
34
     * 
35
     * @return
36
     */
37
    public function findWithTrashed($modelitemId)
38
    {
39
        $this->model = $this->model->withTrashed()->findOrFail($modelitemId);
40
41
        return $this->model;
42
    }
43
44
    /**
45
     * Finds model and includes onlyTrashed() scope in query.
46
     *
47
     * @param int $modelitemId
48
     * 
49
     * @return
50
     */
51
    public function findOnlyTrashed($modelitemId)
52
    {
53
        $this->model = $this->model->onlyTrashed()->findOrFail($modelitemId);
54
55
        return $this->model;
56
    }
57
58
    /**
59
     * Method fired before the Delete action is undertaken.
60
     * 
61
     * @return
62
     */
63
    protected function beforeDelete()
64
    {
65
    }
66
67
    /**
68
     * Delete Action.
69
     *
70
     * Fires off beforeDelete(), doDelete() and afterDelete()
71
     * 
72
     * @param int $modelitemId
73
     * 
74
     * @return
75
     */
76 View Code Duplication
    public function delete($modelitemId)
77
    {
78
        event(new BeforeDelete($this));
79
80
        $this->findWithTrashed($modelitemId);
81
82
        $this->beforeDelete();
83
84
        $this->doDelete();
85
86
        $this->afterDelete();
87
88
        event(new AfterDelete($this));
89
    }
90
91
    /**
92
     * The actual delete action.
93
     * 
94
     * @return
95
     */
96
    private function doDelete()
97
    {
98
        if (!$this->model->trashed()) {
99
            $this->model->delete();
100
            event(new ModelSoftDelete($this));
101
102
            return;
103
        }
104
105
        $this->model->forceDelete();
106
        event(new ModelDelete($this));
107
    }
108
109
    /**
110
     * Method fired after the Delete action is complete.
111
     * 
112
     * @return
113
     */
114
    protected function afterDelete()
115
    {
116
    }
117
118
    /**
119
     * Method fired before the Restore action is undertaken.
120
     * 
121
     * @return
122
     */
123
    protected function beforeRestore()
124
    {
125
    }
126
127
    /**
128
     * Restore Action.
129
     *
130
     * Fires off beforeRestore(), doRestore() and afterRestore()
131
     * 
132
     * @param int $modelitemId
133
     * 
134
     * @return
135
     */
136
    public function restore($modelitemId)
137
    {
138
        event(new BeforeRestore($this));
139
140
        $this->findOnlyTrashed($modelitemId);
141
142
        $this->beforeRestore();
143
144
        $this->doRestore();
145
146
        $this->afterRestore();
147
148
        event(new AfterRestore($this));
149
    }
150
151
    /**
152
     * The actual restore action.
153
     * 
154
     * @return
155
     */
156
    private function doRestore()
157
    {
158
        $this->model->restore();
159
160
        event(new ModelRestore($this));
161
    }
162
163
    /**
164
     * Method fired after the Restore action is complete.
165
     * 
166
     * @return
167
     */
168
    protected function afterRestore()
169
    {
170
    }
171
}
172