Completed
Push — master ( dacc40...01610c )
by Vojtěch
8s
created

ProfileContainer::getDefaultProfile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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