Passed
Push — developer ( 5caef9...3bfca3 )
by Mariusz
17:23
created

CronHandler::addErrorLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Cron.
4
 *
5
 * @package App
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Tomasz Kur <[email protected]>
10
 * @author    Mariusz Krzaczkowski <[email protected]>
11
 */
12
13
namespace App;
14
15
/**
16
 * Class to execute task.
17
 */
18
abstract class CronHandler
19
{
20
	/** @var \vtlib\Cron Cron task instance. */
21
	protected $cronTask;
22
23
	/** @var string Cron task logs. */
24
	protected $logs = '';
25
26
	/**
27
	 * Main function to execute task.
28
	 *
29
	 * @return void
30
	 */
31
	abstract public function process();
32
33
	/**
34
	 * Construct.
35
	 *
36
	 * @param \vtlib\Cron $cronTask
37
	 */
38
	public function __construct(\vtlib\Cron $cronTask)
39
	{
40
		$this->cronTask = $cronTask;
41
	}
42
43
	/**
44
	 * Check cron task timeout.
45
	 *
46
	 * @return bool
47
	 */
48
	public function checkTimeout(): bool
49
	{
50
		return $this->cronTask->checkTimeout();
51
	}
52
53
	/**
54
	 * Update cron task last action time.
55
	 *
56
	 * @return void
57
	 */
58
	public function updateLastActionTime(): void
59
	{
60
		$this->cronTask->updateLastActionTime();
61
	}
62
63
	/**
64
	 * Get cron task logs.
65
	 *
66
	 * @return string
67
	 */
68
	public function getTaskLog(): string
69
	{
70
		return $this->logs;
71
	}
72
73
	/**
74
	 * Add text to logs.
75
	 *
76
	 * @param string $log
77
	 *
78
	 * @return void
79
	 */
80
	public function addTaskLog(string $log): void
81
	{
82
		$this->logs .= $log;
83
	}
84
85
	/**
86
	 * Add error message to log.
87
	 *
88
	 * @param string $message
89
	 *
90
	 * @return void
91
	 */
92
	public function addErrorLog(string $message): void
93
	{
94
		$this->addTaskLog($message);
95
		$this->cronTask->setError($message . '||' . date('Y-m-d H:i:s'));
96
		$this->cronTask->log($message, 'error');
0 ignored issues
show
Bug introduced by
The method log() does not exist on vtlib\Cron. ( Ignorable by Annotation )

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

96
		$this->cronTask->/** @scrutinizer ignore-call */ 
97
                   log($message, 'error');

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...
97
		\App\Log::warning($message, static::class);
98
	}
99
}
100