Completed
Pull Request — master (#73)
by rxu
01:18
created

purge_cache::is_runnable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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;
14
use \phpbb\mediaembed\cache\cache;
15
16
/**
17
 * Mediaembed cron task.
18
 */
19
class purge_cache extends \phpbb\cron\task\base
20
{
21
	/** @var config $config */
22
	protected $config;
23
24
	/** @var purge $mediaembed_cache */
25
	protected $mediaembed_cache;
26
27
	/**
28
	 * Constructor
29
	 *
30
	 * @param config       $config           Config object
31
	 * @param purge        $mediaembed_cache Mediaembed cache object
0 ignored issues
show
Documentation introduced by
Should the type for parameter $mediaembed_cache not be cache?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
32
	 * @access public
33
	 */
34
	public function __construct(config $config, cache $mediaembed_cache)
35
	{
36
		$this->config = $config;
37
		$this->mediaembed_cache = $mediaembed_cache;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mediaembed_cache of type object<phpbb\mediaembed\cache\cache> is incompatible with the declared type object<phpbb\mediaembed\cron\purge> of property $mediaembed_cache.

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...
38
	}
39
40
	/**
41
	 * {@inheritDoc}
42
	 */
43
	public function run()
44
	{
45
		try
46
		{
47
			$this->mediaembed_cache->purge();
48
			$this->config->set('mediaembed_last_gc', time(), false);
49
		}
50
		catch (\RuntimeException $e)
51
		{
52
			return;
53
		}
54
	}
55
56
	/**
57
	 * {@inheritDoc}
58
	 */
59
	public function is_runnable()
60
	{
61
		return (bool) $this->config['media_embed_enable_cache'];
62
	}
63
64
	/**
65
	 * {@inheritDoc}
66
	 */
67
	public function should_run()
68
	{
69
		return $this->config['mediaembed_last_gc'] < strtotime('24 hours ago');
70
	}
71
}
72