Completed
Push — master ( def2bf...0757c5 )
by Roeland
19:59
created

ProviderSet::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * @copyright 2018 Christoph Wurst <[email protected]>
6
 *
7
 * @author 2018 Christoph Wurst <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OC\Authentication\TwoFactorAuth;
27
28
use function array_filter;
29
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
30
use OCP\Authentication\TwoFactorAuth\IProvider;
31
32
/**
33
 * Contains all two-factor provider information for the two-factor login challenge
34
 */
35
class ProviderSet {
36
37
	/** @var IProvider */
38
	private $providers;
39
40
	/** @var bool */
41
	private $providerMissing;
42
43
	/**
44
	 * @param IProvider[] $providers
45
	 * @param bool $providerMissing
46
	 */
47
	public function __construct(array $providers, bool $providerMissing) {
48
		$this->providers = [];
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type object<OCP\Authenticatio...woFactorAuth\IProvider> of property $providers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
		foreach ($providers as $provider) {
50
			$this->providers[$provider->getId()] = $provider;
51
		}
52
		$this->providerMissing = $providerMissing;
53
	}
54
55
	/**
56
	 * @param string $providerId
57
	 * @return IProvider|null
58
	 */
59
	public function getProvider(string $providerId) {
60
		return $this->providers[$providerId] ?? null;
61
	}
62
63
	/**
64
	 * @return IProvider[]
65
	 */
66
	public function getProviders(): array {
67
		return $this->providers;
68
	}
69
70
	/**
71
	 * @return IProvider[]
72
	 */
73
	public function getPrimaryProviders(): array {
74
		return array_filter($this->providers, function(IProvider $provider) {
75
			return !($provider instanceof BackupCodesProvider);
76
		});
77
	}
78
79
	public function isProviderMissing(): bool {
80
		return $this->providerMissing;
81
	}
82
83
}
84