Completed
Pull Request — dev (#50)
by Arnaud
02:55
created

RequestHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 31
rs 10

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
    public function __construct(Registry $registry)
18
    {
19
        $this->registry = $registry;
20
    }
21
22
    public function handle(Request $request)
23
    {
24
        $routeParameters = $request->get('_route_params');
25
26
        if (!$routeParameters) {
27
            throw new Exception('Cannot find admin from request. _route_params parameters for request not found');
28
        }
29
        if (!array_key_exists('_admin', $routeParameters)) {
30
            throw new Exception('Cannot find admin from request. "_admin" route parameter is missing');
31
        }
32
        if (!array_key_exists('_action', $routeParameters)) {
33
            throw new Exception('Cannot find admin action from request. "_action" route parameter is missing');
34
        }
35
36
        return $this
37
            ->registry
38
            ->get($routeParameters['_admin']);
39
    }
40
}
41