MediaWikiCache   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 9 2
A has() 0 3 1
A set() 0 3 1
1
<?php
2
3
namespace SimpleCache\Cache;
4
5
use BagOStuff;
6
7
/**
8
 * Adapter around MediaWikis BagOStuff.
9
 *
10
 * @codeCoverageIgnore
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class MediaWikiCache implements Cache {
16
17
	protected $mediaWikiCache;
18
	protected $expiryTimeInSeconds;
19
20
	/**
21
	 * @param BagOStuff $mediaWikiCache
22
	 * @param int $expiryTimeInSeconds 0 for no expiry time
23
	 */
24
	public function __construct( BagOStuff $mediaWikiCache, $expiryTimeInSeconds = 0 ) {
25
		$this->mediaWikiCache = $mediaWikiCache;
26
		$this->expiryTimeInSeconds = $expiryTimeInSeconds;
27
	}
28
29
	public function get( $key ) {
30
		$value = $this->mediaWikiCache->get( $key );
31
32
		if ( $value === false ) {
33
			return null;
34
		}
35
36
		return $value;
37
	}
38
39
	public function has( $key ) {
40
		return $this->get( $key ) !== null;
41
	}
42
43
	public function set( $key, $value ) {
44
		$this->mediaWikiCache->set( $key, $value, $this->expiryTimeInSeconds );
45
	}
46
47
}
48