Completed
Push — master ( 7a3c27...86f1a1 )
by Christoph
15s queued 13s
created

ProviderFactory::getProvider()   C

Complexity

Conditions 12
Paths 12

Size

Total Lines 26
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 0 Features 3
Metric Value
eloc 25
c 8
b 0
f 3
dl 0
loc 26
rs 6.9666
cc 12
nc 12
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\SMS\Provider;
25
26
use OCA\TwoFactorGateway\Exception\InvalidSmsProviderException;
27
use OCP\AppFramework\IAppContainer;
28
29
class ProviderFactory {
30
31
	/** @var IAppContainer */
32
	private $container;
33
34
	public function __construct(IAppContainer $container) {
35
		$this->container = $container;
36
	}
37
38
	public function getProvider(string $id): IProvider {
39
		switch ($id) {
40
			case PuzzelSMS::PROVIDER_ID:
41
				return $this->container->query(PuzzelSMS::class);
42
			case PlaySMS::PROVIDER_ID:
43
				return $this->container->query(PlaySMS::class);
44
			case WebSms::PROVIDER_ID:
45
				return $this->container->query(WebSms::class);
46
			case ClockworkSMS::PROVIDER_ID:
47
				return $this->container->query(ClockworkSMS::class);
48
			case EcallSMS::PROVIDER_ID:
49
				return $this->container->query(EcallSMS::class);
50
			case VoipMs::PROVIDER_ID:
51
				return $this->container->query(VoipMs::class);
52
			case HuaweiE3531::PROVIDER_ID:
53
				return $this->container->query(HuaweiE3531::class);
54
			case Sms77Io::PROVIDER_ID:
55
				return $this->container->query(Sms77Io::class);
56
			case Ovh::PROVIDER_ID:
57
				return $this->container->query(Ovh::class);
58
			case SpryngSMS::PROVIDER_ID:
59
				return $this->container->query(SpryngSMS::class);
60
			case ClickatellCentral::PROVIDER_ID:
61
				return $this->container->query(ClickatellCentral::class);
62
			default:
63
				throw new InvalidSmsProviderException("Provider <$id> does not exist");
64
		}
65
	}
66
67
}
68