Completed
Push — master ( bd4cbc...df0c76 )
by Arnaud
9s
created

RequestHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 31
ccs 10
cts 13
cp 0.7692
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 18 4
1
<?php
2
3
namespace LAG\AdminBundle\Admin\Request;
4
5
6
use Exception;
7
use LAG\AdminBundle\Admin\Registry\Registry;
8
use Symfony\Component\HttpFoundation\Request;
9
10
class RequestHandler
11
{
12
    /**
13
     * @var Registry
14
     */
15
    protected $registry;
16
17 1
    public function __construct(Registry $registry)
18
    {
19 1
        $this->registry = $registry;
20 1
    }
21
22 1
    public function handle(Request $request)
23
    {
24 1
        $routeParameters = $request->get('_route_params');
25
26 1
        if (!$routeParameters) {
27
            throw new Exception('Cannot find admin from request. _route_params parameters for request not found');
28
        }
29 1
        if (!array_key_exists('_admin', $routeParameters)) {
30
            throw new Exception('Cannot find admin from request. "_admin" route parameter is missing');
31
        }
32 1
        if (!array_key_exists('_action', $routeParameters)) {
33
            throw new Exception('Cannot find admin action from request. "_action" route parameter is missing');
34
        }
35
36 1
        return $this
37
            ->registry
38 1
            ->get($routeParameters['_admin']);
39
    }
40
}
41