Passed
Push — settings-service ( 566350...50862f )
by Matias
03:49
created

FaceRecognitionBackgroundTask::logDebug()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 6
rs 10
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 4
	public function __construct() {
58 4
	}
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 3
	public function setContext(FaceRecognitionContext $context) {
67 3
		$this->context = $context;
68 3
	}
69
70
	/**
71
	 * Wrapper for info logging. It using this log call, it will indent log messages,
72
	 * so there is nice visual that those messages belongs to particular task.
73
	 */
74 1
	protected function logInfo(string $message) {
75 1
		$this->context->logger->logInfo("\t" . $message);
76 1
	}
77
78
	/**
79
	 * Wrapper for debug logging. It using this log call, it will indent log messages,
80
	 * so there is nice visual that those messages belongs to particular task.
81
	 */
82
	protected function logDebug(string $message) {
83
		if ($this->context->verbose) {
84
			$this->context->logger->logDebug("\t" . $message);
85
		}
86
	}
87
}