Completed
Push — master ( 98bac9...c70e3c )
by Morris
29:44 queued 18:50
created

CheckBackupCodes   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A run() 0 10 4
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2018, Roeland Jago Douma <[email protected]>
5
 *
6
 * @author Roeland Jago Douma <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\TwoFactorBackupCodes\BackgroundJob;
26
27
use OC\Authentication\TwoFactorAuth\Manager;
28
use OC\BackgroundJob\QueuedJob;
29
use OCP\Authentication\TwoFactorAuth\IRegistry;
30
use OCP\BackgroundJob\IJobList;
31
use OCP\IUser;
32
use OCP\IUserManager;
33
34
class CheckBackupCodes extends QueuedJob {
35
36
	/** @var IUserManager */
37
	private $userManager;
38
39
	/** @var IJobList */
40
	private $jobList;
41
42
	/** @var Manager */
43
	private $registry;
44
45
	/** @var Manager */
46
	private $twofactorManager;
47
48
	public function __construct(IUserManager $userManager, IJobList $jobList, Manager $twofactorManager, IRegistry $registry) {
49
		$this->userManager = $userManager;
50
		$this->jobList = $jobList;
51
		$this->twofactorManager = $twofactorManager;
52
		$this->registry = $registry;
0 ignored issues
show
Documentation Bug introduced by
It seems like $registry of type object<OCP\Authenticatio...woFactorAuth\IRegistry> is incompatible with the declared type object<OC\Authentication\TwoFactorAuth\Manager> of property $registry.

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...
53
	}
54
55
	protected function run($argument) {
56
		$this->userManager->callForSeenUsers(function(IUser $user) {
57
			$providers = $this->registry->getProviderStates($user);
0 ignored issues
show
Bug introduced by
The method getProviderStates() does not exist on OC\Authentication\TwoFactorAuth\Manager. Did you maybe mean getProvider()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
58
			$isTwoFactorAuthenticated = $this->twofactorManager->isTwoFactorAuthenticated($user);
59
60
			if ($isTwoFactorAuthenticated && isset($providers['backup_codes']) && $providers['backup_codes'] === false) {
61
				$this->jobList->add(RememberBackupCodesJob::class, ['uid' => $user->getUID()]);
62
			}
63
		});
64
	}
65
66
}
67