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

purge::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\cache;
12
13
use \Symfony\Component\Finder\Finder;
14
15
/**
16
 * mediaembed cron task.
17
 */
18
class purge
19
{
20
	/** @var \phpbb\cache\driver\driver_interface */
21
	protected $cache;
22
23
	/**
24
	 * Constructor
25
	 *
26
	 * @param \phpbb\cache\driver\driver_interface  $cache      Cache jbject
27
	 * @access public
28
	 */
29
	public function __construct(\phpbb\cache\driver\driver_interface $cache)
30
	{
31
		$this->cache = $cache;
32
		$this->finder = new Finder();
0 ignored issues
show
Bug introduced by
The property finder does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
	}
34
35
	/**
36
	 * Purge all MediaEmbed cache files
37
	 */
38
	public function purge()
39
	{
40
		$this->finder
41
			->name('http.*')
42
			->in($this->cache->cache_dir)
43
			->files();
44
45
		foreach ($this->finder as $file)
46
		{
47
			$this->cache->remove_file($file->getRealPath());
48
		}
49
	}
50
}
51