Completed
Push — develop ( f099a1...f5bae7 )
by Daniel
20:08
created

blocks_cleanup   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 60
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 5 1
A set_cleaner() 0 3 1
A __construct() 0 3 1
A is_runnable() 0 3 1
A should_run() 0 3 1
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_inteface */
0 ignored issues
show
Bug introduced by
The type blitze\sitemaker\services\blocks\cleaner_inteface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
	protected $cleaner;
19
20
	/**
21
	 * Constructor
22
	 *
23
	 * @param \phpbb\config\config							$config				Config object
24
	 */
25
	public function __construct(\phpbb\config\config $config)
26
	{
27
		$this->config = $config;
28
	}
29
30
	/**
31
	 * We do this instead of the constructor injection to avoid circular reference
32
	 * since phpBB controller.helper service now has a dependency on cron.manager
33
	 *
34
	 * @param \blitze\sitemaker\services\blocks\cleaner_interface $cleaner
35
	 */
36
	public function set_cleaner(\blitze\sitemaker\services\blocks\cleaner_interface $cleaner)
37
	{
38
		$this->cleaner = $cleaner;
0 ignored issues
show
Documentation Bug introduced by
It seems like $cleaner of type blitze\sitemaker\services\blocks\cleaner_interface is incompatible with the declared type blitze\sitemaker\services\blocks\cleaner_inteface of property $cleaner.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
39
	}
40
41
	/**
42 2
	 * Runs this cron task.
43
	 *
44 2
	 * @return void
45 2
	 */
46 2
	public function run()
47 2
	{
48 2
		$this->cleaner->test();
49 2
50 2
		$this->config->set('sitemaker_blocks_cleanup_last_gc', time());
51
	}
52
53
	/**
54
	 * Returns whether this cron task can run, given current board configuration.
55
	 *
56
	 * @return bool
57 1
	 */
58
	public function is_runnable()
59 1
	{
60
		return true;
61 1
	}
62 1
63 1
	/**
64 1
	 * Returns whether this cron task should run now, because enough time
65 1
	 * has passed since it was last run.
66
	 *
67
	 * @return bool
68
	 */
69
	public function should_run()
70
	{
71
		return (int) $this->config['sitemaker_blocks_cleanup_last_gc'] < time() - (int) $this->config['sitemaker_blocks_cleanup_gc'];
72 1
	}
73
}
74