Completed
Pull Request — master (#92)
by Christoph
02:12
created

Factory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getGateway() 0 10 4
A __construct() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Christoph Wurst <[email protected]>
7
 *
8
 * Nextcloud - Two-factor Gateway
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License, version 3,
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
24
namespace OCA\TwoFactorGateway\Service\Gateway;
25
26
use Exception;
27
use OCA\TwoFactorGateway\Service\Gateway\Signal\Gateway as SignalGateway;
28
use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway as SMSGateway;
29
use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway;
30
31
class Factory {
32
33
	/** @var SignalGateway */
34
	private $signalGateway;
35
36
	/** @var SMSGateway */
37
	private $smsGateway;
38
39
	/** @var TelegramGateway */
40
	private $telegramGateway;
41
42
	public function __construct(SignalGateway $signalGateway,
43
								SMSGateway $smsGateway,
44
								TelegramGateway $telegramGateway) {
45
46
		$this->signalGateway = $signalGateway;
47
		$this->smsGateway = $smsGateway;
48
		$this->telegramGateway = $telegramGateway;
49
	}
50
51
	public function getGateway(string $name): IGateway {
52
		switch ($name) {
53
			case 'signal':
54
				return $this->signalGateway;
55
			case 'sms':
56
				return $this->smsGateway;
57
			case 'telegram':
58
				return $this->telegramGateway;
59
			default:
60
				throw new Exception("Invalid gateway <$name>");
61
		}
62
	}
63
64
}
65