Passed
Push — master ( 8c7a35...ac1c73 )
by Blizzz
23:14 queued 14s
created

BundleFetcher::getBundleByIdentifier()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Lukas Reschke <[email protected]>
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Christoph Wurst <[email protected]>
7
 * @author Lukas Reschke <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
namespace OC\App\AppStore\Bundles;
26
27
use OCP\IL10N;
28
29
class BundleFetcher {
30
	private IL10N $l10n;
31
32
	public function __construct(IL10N $l10n) {
33
		$this->l10n = $l10n;
34
	}
35
36
	/**
37
	 * @return Bundle[]
38
	 */
39
	public function getBundles(): array {
40
		return [
41
			new EnterpriseBundle($this->l10n),
42
			new HubBundle($this->l10n),
43
			new GroupwareBundle($this->l10n),
44
			new SocialSharingBundle($this->l10n),
45
			new EducationBundle($this->l10n),
46
		];
47
	}
48
49
	/**
50
	 * Get the bundle with the specified identifier
51
	 *
52
	 * @param string $identifier
53
	 * @return Bundle
54
	 * @throws \BadMethodCallException If the bundle does not exist
55
	 */
56
	public function getBundleByIdentifier(string $identifier): Bundle {
57
		foreach ($this->getBundles() as $bundle) {
58
			if ($bundle->getIdentifier() === $identifier) {
59
				return $bundle;
60
			}
61
		}
62
63
		throw new \BadMethodCallException('Bundle with specified identifier does not exist');
64
	}
65
}
66