Completed
Pull Request — master (#6)
by
unknown
11:57
created

Environment::getDefaultProfile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace SixtyEightPublishers\Application;
4
5
6
class Environment
7
{
8
	const DEFAULT_PROFILE_NAME = 'default';
9
10
	/** @var null|Profile */
11
	private $defaultProfile;
12
13
	/** @var Profile[] */
14
	private $profiles = [];
15
16
	/**
17
	 * @param string        $name
18
	 * @param array         $countries
19
	 * @param array         $languages
20
	 * @param array         $currencies
21
	 * @param array         $domains
22
	 *
23
	 * @return void
24
	 */
25
	public function addProfile($name, array $countries, array $languages, array $currencies, array $domains)
26
	{
27
		$profile = new Profile($countries, $languages, $currencies, $domains);
28
		if ($name === self::DEFAULT_PROFILE_NAME || !$this->defaultProfile)
29
			$this->defaultProfile = $profile;
30
31
		$this->profiles[$name] = $profile;
32
	}
33
34
	/**
35
	 * @return null|\SixtyEightPublishers\Application\Profile
36
	 */
37
	public function getDefaultProfile()
38
	{
39
		return $this->defaultProfile;
40
	}
41
42
	/**
43
	 * @return \SixtyEightPublishers\Application\Profile[]
44
	 */
45
	public function getProfiles()
46
	{
47
		return $this->profiles;
48
	}
49
50
	/**
51
	 * @param string $code
52
	 *
53
	 * @return \SixtyEightPublishers\Application\Profile
54
	 */
55
	public function getProfile($code)
56
	{
57
		if (!array_key_exists($code, $this->profiles))
58
			throw new NonExistentProfileException("Profile with name \"{$code}\" doesn't exists.");
59
60
		return $this->profiles[$code];
61
	}
62
}
63