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

Element

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 0
cts 0
cp 0
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tions::setOption() 0 7 2
A tions::getOption() 0 11 3
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
}