ServiceIdGenerator::generateForBundleClass()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 3
1
<?php
2
3
namespace Knp\RadBundle\DependencyInjection;
4
5
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
6
use Symfony\Component\DependencyInjection\Container;
7
8
class ServiceIdGenerator
9
{
10
    public function generateForBundleClass(BundleInterface $bundle, $className, $withSuffix = false)
11
    {
12
        $namespace = $bundle->getNamespace();
13
        $extension = $bundle->getContainerExtension();
14
15
        $extensionAlias = $extension->getAlias();
16
17
        $bundleClass = substr($className, strlen($namespace) + 1);
18
        $bundlePart = str_replace('\\', '.', Container::underscore($bundleClass));
19
20
        if (false !== $withSuffix) {
21
            $bundlePart .= '_'.$withSuffix;
22
        }
23
24
        return sprintf('%s.%s', $extensionAlias, $bundlePart);
25
    }
26
}
27