1 | <?php |
||||
2 | |||||
3 | namespace Larapie\Actions\Concerns; |
||||
4 | |||||
5 | use Illuminate\Auth\Access\AuthorizationException; |
||||
6 | use Illuminate\Support\Facades\Gate; |
||||
7 | |||||
8 | trait ResolvesAuthorization |
||||
9 | { |
||||
10 | 53 | protected function resolveAuthorization() |
|||
11 | { |
||||
12 | 53 | if (! $this->passesAuthorization()) { |
|||
13 | 2 | $this->failedAuthorization(); |
|||
14 | } |
||||
15 | |||||
16 | 51 | return $this; |
|||
17 | } |
||||
18 | |||||
19 | 55 | public function passesAuthorization() |
|||
20 | { |
||||
21 | 55 | if (method_exists($this, 'authorize')) { |
|||
22 | 13 | return $this->resolveAndCall($this, 'authorize'); |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
23 | } |
||||
24 | |||||
25 | 48 | return true; |
|||
26 | } |
||||
27 | |||||
28 | 2 | protected function failedAuthorization() |
|||
29 | { |
||||
30 | 2 | throw new AuthorizationException('This action is unauthorized.'); |
|||
31 | } |
||||
32 | |||||
33 | 2 | protected function can($ability, $arguments = []) |
|||
34 | { |
||||
35 | 2 | return Gate::forUser($this->user())->allows($ability, $arguments); |
|||
0 ignored issues
–
show
It seems like
user() 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
![]() |
|||||
36 | } |
||||
37 | } |
||||
38 |