ParametersExtractor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 15
c 1
b 0
f 0
dl 0
loc 36
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 16 4
A getResourceName() 0 7 2
A getOperationName() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Request\Extractor;
6
7
use LAG\AdminBundle\Exception\Exception;
8
use LAG\AdminBundle\LAGAdminBundle;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class ParametersExtractor implements ParametersExtractorInterface
12
{
13 2
    public function getResourceName(Request $request): string
14
    {
15 2
        if (!$this->supports($request)) {
16 1
            throw new Exception('No admin resource was found in the request. The route is wrongly configured');
17
        }
18
19 1
        return $request->get('_route_params')[LAGAdminBundle::REQUEST_PARAMETER_ADMIN];
20
    }
21
22 2
    public function getOperationName(Request $request): string
23
    {
24 2
        if (!$this->supports($request)) {
25 1
            throw new Exception('No action resource was found in the request. The route is wrongly configured');
26
        }
27
28 1
        return $request->get('_route_params')[LAGAdminBundle::REQUEST_PARAMETER_ACTION];
29
    }
30
31 9
    public function supports(Request $request): bool
32
    {
33 9
        $routeParameters = $request->get('_route_params');
34
35 9
        if (!\is_array($routeParameters)) {
36 1
            return false;
37
        }
38
39
        if (
40 8
            !isset($routeParameters[LAGAdminBundle::REQUEST_PARAMETER_ADMIN]) ||
41 8
            !isset($routeParameters[LAGAdminBundle::REQUEST_PARAMETER_ACTION])
42
        ) {
43 5
            return false;
44
        }
45
46 3
        return true;
47
    }
48
}
49