Passed
Push — master ( 2a1535...3821a9 )
by Anthony
03:07
created

Globals::getPackageDevName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Service;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
7
class Globals
8
{
9
	/**
10
	 * @var ContainerInterface
11
	 */
12
	private $container;
13
	
14
	public function __construct(ContainerInterface $container)
15
	{
16
		$this->container = $container;
17
	}
18
	
19
	/**
20
	 * this method send path on dev mode to correct write package name
21
	 * @param string $package
22
	 * @return string
23
	 */
24
	private function getPackageDevName(string $package) {
25
		$bundle = explode("/", $package)[1];
26
		$explode = explode("-", $bundle);
27
		
28
		$package_name = "";
29
		
30
		foreach ($explode as $string) {
31
			$package_name .= ucfirst($string);
32
		}
33
		
34
		return $package_name;
35
	}
36
	
37
	/**
38
	 * this method send base bundle path related to ribs-admin
39
	 * @param string|null $package
40
	 * @return string
41
	 */
42
	public function getBaseBundlePath(string $package = "piou-piou/ribs-admin-bundle"): string
43
	{
44
		$path = explode("/", __DIR__);
45
		array_pop($path);
46
		
47
		$dev_mode = $this->container->getParameter("ribs_admin")["dev_mode"];
48
		
49
		if ($dev_mode === true) {
50
			$package = "lib/".$this->getPackageDevName($package);
51
		}
52
		
53
		return implode("/", $path)."/../../" . $package;
54
	}
55
}