Completed
Push — move ( 889447...795827 )
by Jeroen De
05:20
created

ElementOptions   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 57
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setOption() 0 7 2
A getOption() 0 11 3
A hasOption() 0 7 2
1
<?php
2
3
namespace Maps;
4
5
class ElementOptions {
6
7
	private $options = [];
8
9
	/**
10
	 * @since 3.0
11
	 *
12
	 * @param string $name
13
	 * @param mixed $value
14
	 *
15
	 * @throws \InvalidArgumentException
16
	 */
17 8
	public function setOption( $name, $value ) {
18 8
		if ( !is_string( $name ) ) {
19
			throw new \InvalidArgumentException( 'Option name should be a string' );
20
		}
21
22 8
		$this->options[$name] = $value;
23 8
	}
24
25
	/**
26
	 * @since 3.0
27
	 *
28
	 * @param string $name
29
	 *
30
	 * @throws \InvalidArgumentException
31
	 * @throws \OutOfBoundsException
32
	 */
33 8
	public function getOption( $name ) {
34 8
		if ( !is_string( $name ) ) {
35
			throw new \InvalidArgumentException( 'Option name should be a string' );
36
		}
37
38 8
		if ( !array_key_exists( $name, $this->options ) ) {
39
			throw new \OutOfBoundsException( 'Tried to obtain option "' . $name . '" while it has not been set' );
40
		}
41
42 8
		return $this->options[$name];
43
	}
44
45
	/**
46
	 * @since 3.0
47
	 *
48
	 * @param string $name
49
	 *
50
	 * @return boolean
51
	 * @throws \InvalidArgumentException
52
	 */
53 18
	public function hasOption( $name ) {
54 18
		if ( !is_string( $name ) ) {
55
			throw new \InvalidArgumentException( 'Option name should be a string' );
56
		}
57
58 18
		return array_key_exists( $name, $this->options );
59
	}
60
61
}