Passed
Pull Request — master (#686)
by Vitor
04:21
created

Factory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 7
eloc 17
dl 0
loc 30
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPrefix() 0 3 1
A getBaseClass() 0 3 1
A getSuffix() 0 3 1
A get() 0 14 4
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * SPDX-FileCopyrightText: 2024 Christoph Wurst <[email protected]>
7
 * SPDX-License-Identifier: AGPL-3.0-or-later
8
 */
9
10
namespace OCA\TwoFactorGateway\Provider\Channel\SMS;
11
12
use OCA\TwoFactorGateway\Exception\InvalidProviderException;
13
use OCA\TwoFactorGateway\Provider\AFactory;
14
use OCA\TwoFactorGateway\Provider\AProvider;
15
use OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\IProvider;
16
17
/** @extends AFactory<AProvider> */
18
class Factory extends AFactory {
19 1
	#[\Override]
20
	protected function getPrefix(): string {
21 1
		return 'OCA\\TwoFactorGateway\\Provider\\Channel\\SMS\\Provider\\Drivers\\';
22
	}
23
24 1
	#[\Override]
25
	protected function getSuffix(): string {
26 1
		return '';
27
	}
28
29 1
	#[\Override]
30
	protected function getBaseClass(): string {
31 1
		return IProvider::class;
32
	}
33
34 1
	#[\Override]
35
	public function get(string $name): object {
36 1
		if (isset($this->instances[$name])) {
37
			return $this->instances[$name];
38
		}
39 1
		foreach ($this->getFqcnList() as $fqcn) {
40 1
			$instance = \OCP\Server::get($fqcn);
41 1
			if ($instance->getSettings()->id === $name) {
42 1
				$instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class));
43 1
				$this->instances[$name] = $instance;
44 1
				return $instance;
45
			}
46
		}
47
		throw new InvalidProviderException("Provider <$name> does not exist");
48
	}
49
}
50