Passed
Push — release-3.2.0 ( 8165d1...607af8 )
by Daniel
03:27
created

blocks_cleanup::clean_styles()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 0
dl 0
loc 24
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\cron;
11
12
class blocks_cleanup extends \phpbb\cron\task\base
13
{
14
	/** @var \phpbb\config\config */
15
	protected $config;
16
17
	/** @var \blitze\sitemaker\services\blocks\cleaner */
18
	protected $cleaner;
19
20
	/**
21
	 * Constructor
22
	 *
23
	 * @param \phpbb\config\config							$config				Config object
24
	 * @param \blitze\sitemaker\services\blocks\cleaner		$cleaner			Block cleaning service
25
	 */
26
	public function __construct(\phpbb\config\config $config, \blitze\sitemaker\services\blocks\cleaner $cleaner)
27
	{
28
		$this->config = $config;
29
		$this->cleaner = $cleaner;
30
	}
31
32
	/**
33
	 * Runs this cron task.
34
	 *
35
	 * @return void
36
	 */
37
	public function run()
38
	{
39
		$this->cleaner->test();
40
41
		$this->config->set('sitemaker_blocks_cleanup_last_gc', time());
42
	}
43
44
	/**
45
	 * Returns whether this cron task can run, given current board configuration.
46
	 *
47
	 * @return bool
48
	 */
49
	public function is_runnable()
50
	{
51
		return true;
52
	}
53
54
	/**
55
	 * Returns whether this cron task should run now, because enough time
56
	 * has passed since it was last run.
57
	 *
58
	 * @return bool
59
	 */
60
	public function should_run()
61
	{
62
		return (int) $this->config['sitemaker_blocks_cleanup_last_gc'] < time() - (int) $this->config['sitemaker_blocks_cleanup_gc'];
63
	}
64
}
65