Options   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 75
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A newFromGlobals() 0 14 2
A set() 0 3 1
A has() 0 3 2
A get() 0 8 2
1
<?php
2
3
namespace SUC;
4
5
use InvalidArgumentException;
6
7
/**
8
 * @license GNU GPL v2+
9
 * @since 1.0
10
 *
11
 * @author mwjames
12
 */
13
class Options {
14
15
	/**
16
	 * @var array
17
	 */
18
	private $options = array();
19
20
	/**
21
	 * @since 1.0
22
	 *
23
	 * @param array $options
24
	 */
25 9
	public function __construct( array $options = array() ) {
26 9
		$this->options = $options;
27 9
	}
28
29
	/**
30
	 * @since 1.0
31
	 *
32
	 * @return self
33
	 */
34 6
	public static function newFromGlobals() {
35 6
		$GLOBALS['sucgCachePrefix'] = $GLOBALS['wgCachePrefix'] === false ? wfWikiID() : $GLOBALS['wgCachePrefix'];
36
37
		$configuration = array(
38 6
			'tooltipRequestCacheTTL'       => $GLOBALS['sucgTooltipRequestCacheLifetime'],
39 6
			'cachePrefix'                  => $GLOBALS['sucgCachePrefix'],
40 6
			'enabledNamespaceWithTemplate' => $GLOBALS['sucgEnabledNamespaceWithTemplate'],
41 6
			'enabledForAnonUsers'          => $GLOBALS['sucgEnabledForAnonUser'],
42 6
			'backendParserCacheLifetime'   => $GLOBALS['sucgBackendParserCacheLifetime'],
43 6
			'backendParserCacheType'       => $GLOBALS['sucgBackendParserCacheType']
44 6
		);
45
46 6
		return new self( $configuration );
47
	}
48
49
	/**
50
	 * @since 1.0
51
	 *
52
	 * @param string $key
53
	 * @param mixed $value
54
	 */
55 1
	public function set( $key, $value ) {
56 1
		$this->options[$key] = $value;
57 1
	}
58
59
	/**
60
	 * @since 1.0
61
	 *
62
	 * @param string $key
63
	 *
64
	 * @return boolean
65
	 */
66 8
	public function has( $key ) {
67 8
		return isset( $this->options[$key] ) || array_key_exists( $key, $this->options );
68
	}
69
70
	/**
71
	 * @since 1.0
72
	 *
73
	 * @param string $key
74
	 *
75
	 * @return string
76
	 * @throws InvalidArgumentException
77
	 */
78 2
	public function get( $key ) {
79
80 2
		if ( $this->has( $key ) ) {
81 1
			return $this->options[$key];
82
		}
83
84 1
		throw new InvalidArgumentException( "{$key} is an unregistered option" );
85
	}
86
87
}
88