Passed
Push — dependabot/npm_and_yarn/decode... ( a4b439 )
by
unknown
11:31
created

FaceRecognitionBackgroundTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 39
ccs 8
cts 9
cp 0.8889
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A logInfo() 0 2 1
A setContext() 0 2 1
A logDebug() 0 3 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017, Matias De lellis <[email protected]>
4
 * @copyright Copyright (c) 2018, Branko Kokanovic <[email protected]>
5
 *
6
 * @author Branko Kokanovic <[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
namespace OCA\FaceRecognition\BackgroundJob;
25
26
use OCA\FaceRecognition\BackgroundJob\FaceRecognitionContext;
27
28
/**
29
 * Interface that each face recognition background task should implement
30
 */
31
interface IFaceRecognitionBackgroundTask {
32
	/**
33
	 * Returns task's description.
34
	 *
35
	 * @return string Description of what task do
36
	 */
37
	public function description();
38
39
	/**
40
	 * Executes task.
41
	 *
42
	 * @param FaceRecognitionContext $context Face recognition context
43
	 * @return \Generator|bool Since we are yielding, return type is either Generator, or boolean (actual return).
44
	 * Return value specifies should we continue execution. True if we should continue, false if we should bail out.
45
	 */
46
	public function execute(FaceRecognitionContext $context);
47
}
48
49
/**
50
 * Abstract implementation for background task, serves as a helper for common functions.
51
 */
52
abstract class FaceRecognitionBackgroundTask implements IFaceRecognitionBackgroundTask {
53
54
	/** @var FaceRecognitionContext $context */
55
	protected $context;
56
57 15
	public function __construct() {
58 15
	}
59
60
	/**
61
	 * Sets context for a given task, so it can be accessed in task (without a need to dragging it around from execute() method).
62
	 * Currently public, because of tests (ideally it should be protected).
63
	 *
64
	 * @param FaceRecognitionContext $context Context
65
	 *
66
	 * @return void
67
	 */
68 13
	public function setContext(FaceRecognitionContext $context): void {
69 13
		$this->context = $context;
70
	}
71
72
	/**
73
	 * Wrapper for info logging. It using this log call, it will indent log messages,
74
	 * so there is nice visual that those messages belongs to particular task.
75
	 *
76
	 * @return void
77
	 */
78 12
	protected function logInfo(string $message): void {
79 12
		$this->context->logger->logInfo("\t" . $message);
80
	}
81
82
	/**
83
	 * Wrapper for debug logging. It using this log call, it will indent log messages,
84
	 * so there is nice visual that those messages belongs to particular task.
85
	 *
86
	 * @return void
87
	 */
88 9
	protected function logDebug(string $message): void {
89 9
		if ($this->context->verbose) {
90
			$this->context->logger->logDebug("\t" . $message);
91
		}
92
	}
93
}