Factory   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
eloc 22
c 1
b 0
f 1
dl 0
loc 36
ccs 18
cts 20
cp 0.9
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSuffix() 0 3 1
A getBaseClass() 0 3 1
A getPrefix() 0 3 1
A get() 0 19 6
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
	private array $instancesByFqcn = [];
19 2
	#[\Override]
20
	protected function getPrefix(): string {
21 2
		return 'OCA\\TwoFactorGateway\\Provider\\Channel\\Telegram\\Provider\\Drivers\\';
22
	}
23
24 2
	#[\Override]
25
	protected function getSuffix(): string {
26 2
		return '';
27
	}
28
29 2
	#[\Override]
30
	protected function getBaseClass(): string {
31 2
		return AProvider::class;
32
	}
33
34 6
	#[\Override]
35
	public function get(string $name): object {
36 6
		if (isset($this->instancesByFqcn[$name])) {
37 6
			return $this->instancesByFqcn[$name];
38
		}
39 2
		if (isset($this->instances[$name])) {
40
			return $this->instances[$name];
41
		}
42 2
		foreach ($this->getFqcnList() as $fqcn) {
43 2
			$instance = \OCP\Server::get($fqcn);
44 2
			$settings = $instance->getSettings();
45 2
			if ($fqcn === $name || $settings->id === $name) {
46 2
				$instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class));
47 2
				$this->instances[$name] = $instance;
48 2
				$this->instancesByFqcn[$fqcn] = $instance;
49 2
				return $instance;
50
			}
51
		}
52
		throw new InvalidProviderException("Provider <$name> does not exist");
53
	}
54
}
55