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

ElementOptions::setOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 5
cp 0.8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.032
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
}