BundleNameFromClassName::getBundleName()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 6
nc 3
nop 0
1
<?php
2
namespace kujaff\VersionsBundle\Model;
3
4
/**
5
 * Define a protected property ContainerInterface $container and define it in __construct(ContainerInterface $container)
6
 */
7
trait BundleNameFromClassName
8
{
9
10
	/**
11
	 * Return bundle name, search for it in class namespace
12
	 *
13
	 * @return string
14
     * @throws \Exception
15
	 */
16
	public function getBundleName()
17
	{
18
		$parts = array_reverse(explode('\\', get_called_class()));
19
		foreach ($parts as $part) {
20
			if (substr($part, -6) == 'Bundle') {
21
				return $part;
22
			}
23
		}
24
		throw \Exception('Bundle name cannot be found in "' . get_called_class() . '" class name.');
25
	}
26
27
}
28