Passed
Pull Request — master (#442)
by Matias
03:42 queued 01:57
created

UserHooks::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2016, Roeland Jago Douma <[email protected]>
5
 * @copyright Copyright (c) 2017-2021 Matias De lellis <[email protected]>
6
 *
7
 * @author Roeland Jago Douma <[email protected]>
8
 * @author Matias De lellis <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\FaceRecognition\Hooks;
28
29
use OCP\ILogger;
30
use OCP\IUserManager;
31
32
use OCA\FaceRecognition\Service\FaceManagementService;
33
34
35
class UserHooks {
36
37
	/** @var ILogger Logger */
38
	private $logger;
39
40
	/** @var IUserManager */
41
	private $userManager;
42
43
	/** @var FaceManagementService */
44
	private $faceManagementService;
45
46
	/**
47
	 * Watcher constructor.
48
	 *
49
	 * @param ILogger $logger
50
	 * @param IUserManager $userManager
51
	 * @param FaceManagementService $faceManagementService
52
	 */
53
	public function __construct(ILogger               $logger,
54
	                            IUserManager          $userManager,
55
	                            FaceManagementService $faceManagementService)
56
	{
57
		$this->logger                = $logger;
58
		$this->userManager           = $userManager;
59
		$this->faceManagementService = $faceManagementService;
60
	}
61
62 28
	public function register() {
63
		// Watch for user deletion, so we clean up user data, after user gets deleted
64
		$this->userManager->listen('\OC\User', 'postDelete', function (\OC\User\User $user) {
0 ignored issues
show
Bug introduced by
The type OC\User\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The method listen() does not exist on OCP\IUserManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
		$this->userManager->/** @scrutinizer ignore-call */ 
65
                      listen('\OC\User', 'postDelete', function (\OC\User\User $user) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65 28
			$this->postUserDelete($user);
66 28
		});
67
	}
68
69
	/**
70
	 * A user has been deleted. Cleanup everything from this user.
71
	 *
72
	 * @param \OC\User\User $user Deleted user
73
	 */
74 28
	public function postUserDelete(\OC\User\User $user) {
75 28
		$userId = $user->getUid();
76 28
		$this->faceManagementService->resetAllForUser($userId);
77 28
		$this->logger->info("Removed all face recognition data for deleted user " . $userId);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\ILogger::info() has been deprecated: 20.0.0 use \Psr\Log\LoggerInterface::info ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

77
		/** @scrutinizer ignore-deprecated */ $this->logger->info("Removed all face recognition data for deleted user " . $userId);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
78 28
	}
79
}
80