ResolvesAuthorization::failedAuthorization()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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
It seems like resolveAndCall() 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

22
            return $this->/** @scrutinizer ignore-call */ resolveAndCall($this, 'authorize');
Loading history...
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
Bug introduced by
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 ignore-call  annotation

35
        return Gate::forUser($this->/** @scrutinizer ignore-call */ user())->allows($ability, $arguments);
Loading history...
36
    }
37
}
38