Passed
Pull Request — master (#686)
by Vitor
06:35 queued 01:51
created

Factory::isValid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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\Channel\SMS\Provider\AProvider;
15
16
/** @extends AFactory<AProvider> */
17
class Factory extends AFactory {
18 1
	#[\Override]
19
	protected function getPrefix(): string {
20 1
		return 'OCA\\TwoFactorGateway\\Provider\\Channel\\SMS\\Provider\\Drivers\\';
21
	}
22
23 1
	#[\Override]
24
	protected function getSuffix(): string {
25 1
		return '';
26
	}
27
28 1
	#[\Override]
29
	protected function getBaseClass(): string {
30 1
		return AProvider::class;
31
	}
32
33 1
	#[\Override]
34
	public function get(string $name): object {
35 1
		if (isset($this->instances[$name])) {
36
			return $this->instances[$name];
37
		}
38 1
		foreach ($this->getFqcnList() as $fqcn) {
39 1
			$instance = \OCP\Server::get($fqcn);
40 1
			if ($instance->getSettings()->id === $name) {
41 1
				$instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class));
42 1
				$this->instances[$name] = $instance;
43 1
				return $instance;
44
			}
45
		}
46
		throw new InvalidProviderException("Provider <$name> does not exist");
47
	}
48
}
49