Options   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 53
rs 10
c 0
b 0
f 0
ccs 12
cts 12
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A set() 0 3 1
A has() 0 3 2
A get() 0 8 2
1
<?php
2
3
namespace SBL;
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 = [];
19
20
	/**
21
	 * @since 1.0
22
	 */
23 3
	public function __construct( array $options = [] ) {
24 3
		$this->options = $options;
25 3
	}
26
27
	/**
28
	 * @since 1.0
29
	 *
30
	 * @param string $key
31
	 * @param mixed $value
32
	 */
33 1
	public function set( $key, $value ) {
34 1
		$this->options[$key] = $value;
35 1
	}
36
37
	/**
38
	 * @since 1.0
39
	 *
40
	 * @param string $key
41
	 *
42
	 * @return boolean
43
	 */
44 2
	public function has( $key ) {
45 2
		return isset( $this->options[$key] ) || array_key_exists( $key, $this->options );
46
	}
47
48
	/**
49
	 * @since 1.0
50
	 *
51
	 * @param string $key
52
	 *
53
	 * @return string
54
	 * @throws InvalidArgumentException
55
	 */
56 2
	public function get( $key ) {
57
58 2
		if ( $this->has( $key ) ) {
59 1
			return $this->options[$key];
60
		}
61
62 1
		throw new InvalidArgumentException( "{$key} is an unregistered option" );
63
	}
64
65
}
66