Completed
Pull Request — master (#90)
by Arnaud
03:09 queued 01:17
created

RouteNameGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 27
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B generate() 0 24 2
1
<?php
2
3
namespace LAG\AdminBundle\Routing;
4
5
use Exception;
6
use LAG\AdminBundle\Admin\Configuration\AdminConfiguration;
7
8
class RouteNameGenerator
9
{
10
    public function generate($actionName, $adminName, AdminConfiguration $configuration)
11
    {
12
        if (!array_key_exists($actionName, $configuration->getParameter('actions'))) {
13
            throw new Exception(
14
                sprintf('Invalid action name %s for admin %s (available action are: %s)',
15
                    $actionName,
16
                    $adminName,
17
                    implode(', ', array_keys($configuration->getParameter('actions'))))
18
            );
19
        }
20
        // generate the route name using the configured pattern
21
        $routeName = str_replace(
22
            '{admin}',
23
            strtolower($adminName),
24
            $configuration->getParameter('routing_name_pattern')
25
        );
26
        $routeName = str_replace(
27
            '{action}',
28
            $actionName,
29
            $routeName
30
        );
31
    
32
        return $routeName;
33
    }
34
}
35