HandlesAuthorization   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 24
ccs 5
cts 5
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 10 2
1
<?php namespace Pz\LaravelDoctrine\Rest\Traits;
2
3
use Illuminate\Auth\Access\AuthorizationException;
4
5
use Illuminate\Contracts\Auth\Access\Gate;
6
use Pz\Doctrine\Rest\Exceptions\RestException;
7
use Pz\Doctrine\Rest\RestRequest;
8
9
use Symfony\Component\HttpFoundation\Response;
10
11
trait HandlesAuthorization
12
{
13
    /**
14
     * Action ability.
15
     *
16
     * @return string
17
     */
18
    abstract protected function restAbility();
19
20
    /**
21
     * @param RestRequest   $request
22
     * @param array|mixed   $arguments
23
     * @throws RestException
24
     */
25 7
    public function authorize($request, $arguments = [])
26
    {
27
        try {
28
29
            /** @var Gate $gate */
30 7
            $gate = app(Gate::class);
31 7
            $gate->authorize($this->restAbility(), $arguments);
32
33 1
        } catch (AuthorizationException $e) {
34 1
            throw RestException::createForbidden($e->getMessage());
35
        }
36 6
    }
37
}
38