ParametersExtractor::getOperationName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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