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

RouteNameGenerator::generate()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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