purge_cache::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 *
4
 * phpBB Media Embed PlugIn extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2020 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\mediaembed\cron;
12
13
use phpbb\config\config;
0 ignored issues
show
Bug introduced by
The type phpbb\config\config 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...
14
use phpbb\mediaembed\cache\cache;
15
16
/**
17
 * Media Embed cron task.
18
 */
19
class purge_cache extends \phpbb\cron\task\base
0 ignored issues
show
Bug introduced by
The type phpbb\cron\task\base 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...
20
{
21
	/** @var config $config */
22
	protected $config;
23
24
	/** @var cache $cache */
25
	protected $cache;
26
27
	/**
28
	 * Constructor
29
	 *
30
	 * @param config $config Config object
31
	 * @param cache  $cache  MediaEmbed cache object
32
	 */
33
	public function __construct(config $config, cache $cache)
34
	{
35
		$this->config = $config;
36
		$this->cache = $cache;
37
	}
38
39
	/**
40
	 * {@inheritDoc}
41
	 */
42
	public function run()
43
	{
44
		$this->cache->purge_mediaembed_cache();
45
		$this->config->set('mediaembed_last_gc', time(), false);
46
	}
47
48
	/**
49
	 * {@inheritDoc}
50
	 */
51
	public function is_runnable()
52
	{
53
		return (bool) $this->config['media_embed_enable_cache'];
54
	}
55
56
	/**
57
	 * {@inheritDoc}
58
	 */
59
	public function should_run()
60
	{
61
		return $this->config['mediaembed_last_gc'] < strtotime('24 hours ago');
62
	}
63
}
64