Passed
Push — master ( d021a5...a13070 )
by Sam
03:47 queued 12s
created

ImageCache   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 0
dl 0
loc 61
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCacheUrl() 0 3 1
A __construct() 0 4 1
A getCachePath() 0 3 1
A get() 0 3 1
A has() 0 3 1
1
<?php
2
3
/**
4
 * Simple image caching component.
5
 *
6
 * @author Sam Stenvall <[email protected]>
7
 * @copyright Copyright &copy; Sam Stenvall 2013-
8
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
9
 */
10
class ImageCache
11
{
12
13
	/**
14
	 * @var string the absolute path to the cache
15
	 */
16
	private $_cachePath;
17
18
	/**
19
	 * @var string the URL to the cache
20
	 */
21
	private $_cacheUrl;
22
23
	/**
24
	 * Class constructor
25
	 */
26
	public function __construct()
27
	{
28
		$this->_cachePath = realpath(Yii::app()->basePath.'/..').'/images/image-cache';
29
		$this->_cacheUrl = Yii::app()->baseUrl.'/images/image-cache';
30
	}
31
32
	/**
33
	 * Checks if the given file exists in the cache
34
	 * @param string $filename
35
	 * @return boolean
36
	 */
37
	public function has($filename)
38
	{
39
		return file_exists($this->_cachePath.DIRECTORY_SEPARATOR.$filename);
40
	}
41
42
	/**
43
	 * Returns the URL to the given file (assuming it is cached)
44
	 * @param string $filename
45
	 * @return string
46
	 */
47
	public function get($filename)
48
	{
49
		return $this->_cacheUrl.'/'.$filename;
50
	}
51
52
	/**
53
	 * Getter for _cachePath
54
	 * @return string
55
	 */
56
	public function getCachePath()
57
	{
58
		return $this->_cachePath;
59
	}
60
61
	/**
62
	 * Getter for _cacheUrl
63
	 * @return string
64
	 */
65
	public function getCacheUrl()
66
	{
67
		return $this->_cacheUrl;
68
	}
69
70
}