Passed
Push — test-scrutinizer-new-analyser ( 748b29 )
by Branko
05:41
created

FaceRecognitionBackgroundTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 18.18%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 32
ccs 2
cts 11
cp 0.1818
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A logInfo() 0 2 1
A setContext() 0 2 1
A __construct() 0 1 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
	 */
44
	public function do(FaceRecognitionContext $context);
45
}
46
47
/**
48
 * Abstract implementation for background task, serves as a helper for common functions.
49
 */
50
abstract class FaceRecognitionBackgroundTask implements IFaceRecognitionBackgroundTask {
51
52
	/** @var FaceRecognitionContext $context */
53
	protected $context;
54
55 2
	public function __construct() {
56 2
	}
57
58
	/**
59
	 * Sets context for a given task, so it can accessed in task (without a need to dragging it around from do() method).
60
	 *
61
	 * @param FaceRecognitionContext $context Context
62
	 */
63
	protected function setContext(FaceRecognitionContext $context) {
64
		$this->context = $context;
65
	}
66
67
	/**
68
	 * Wrapper for info logging. It using this log call, it will indent log messages,
69
	 * so there is nice visual that those messages belongs to particular task.
70
	 */
71
	protected function logInfo(string $message) {
72
		$this->context->logger->logInfo("\t" . $message);
73
	}
74
75
	/**
76
	 * Wrapper for debug logging. It using this log call, it will indent log messages,
77
	 * so there is nice visual that those messages belongs to particular task.
78
	 */
79
	protected function logDebug(string $message) {
80
		if ($this->context->verbose) {
81
			$this->context->logger->logDebug("\t" . $message);
82
		}
83
	}
84
}