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

Factory::getSuffix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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