Passed
Pull Request — master (#42)
by
unknown
04:10
created

ContentFilter::getContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace SilverStripe\VersionFeed\Filters;
4
5
use SilverStripe\VersionFeed\VersionFeedController;
6
use SilverStripe\Core\Config\Configurable;
7
use Psr\SimpleCache\CacheInterface;
8
use SilverStripe\Core\Injector\Injector;
9
10
11
12
/**
13
 * Conditionally executes a given callback, attempting to return the desired results
14
 * of its execution.
15
 */
16
abstract class ContentFilter {
17
18
	use configurable;
19
	
20
	/**
21
	 * Nested content filter
22
	 *
23
	 * @var ContentFilter
24
	 */
25
	protected $nestedContentFilter;
26
27
	/**
28
	 * Cache lifetime
29
	 *
30
	 * @config
31
	 * @var int
32
	 */
33
	private static $cache_lifetime = 300;
0 ignored issues
show
introduced by
The private property $cache_lifetime is not used, and could be removed.
Loading history...
34
	
35
	public function __construct($nestedContentFilter = null) {
36
		$this->nestedContentFilter = $nestedContentFilter;
37
	}
38
	
39
	/**
40
	 * Gets the cache to use
41
	 * 
42
	 * @return Zend_Cache_Frontend
0 ignored issues
show
Bug introduced by
The type SilverStripe\VersionFeed...ers\Zend_Cache_Frontend 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...
43
	 */
44
	protected function getCache() {
45
		return Injector::inst()->get(
46
			CacheInterface::class . '.VersionFeedController'
47
		);
48
	}
49
	
50
	/**
51
	 * Evaluates the result of the given callback
52
	 * 
53
	 * @param string $key Unique key for this
54
	 * @param callable $callback Callback for evaluating the content
55
	 * @return mixed Result of $callback()
56
	 */
57
	public function getContent($key, $callback) {
58
		if($this->nestedContentFilter) {
59
			return $this->nestedContentFilter->getContent($key, $callback);
60
		} else {
61
			return call_user_func($callback);
62
		}
63
	}
64
}
65