DataValueHandlers::getMainSnakHandlers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\QueryEngine\SQLStore;
4
5
use OutOfBoundsException;
6
7
/**
8
 * @since 0.1
9
 *
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class DataValueHandlers {
14
15
	/**
16
	 * @var DataValueHandler[]
17
	 */
18
	private $mainSnakHandlers = array();
19
20
	/**
21
	 * @var DataValueHandler[]
22
	 */
23
	private $qualifierHandlers = array();
24
25
	public function addMainSnakHandler( $dataTypeId, DataValueHandler $handler ) {
26
		$this->mainSnakHandlers[$dataTypeId] = $handler;
27
	}
28
29
	public function addQualifierHandler( $dataTypeId, DataValueHandler $handler ) {
30
		$this->qualifierHandlers[$dataTypeId] = $handler;
31
	}
32
33
	/**
34
	 * @param string $dataTypeId
35
	 *
36
	 * @return DataValueHandler
37
	 * @throws OutOfBoundsException
38
	 */
39
	public function getMainSnakHandler( $dataTypeId ) {
40
		if ( !array_key_exists( $dataTypeId, $this->mainSnakHandlers ) ) {
41
			throw new OutOfBoundsException( "There is no main snak DataValueHandler for '$dataTypeId'." );
42
		}
43
44
		return $this->mainSnakHandlers[$dataTypeId];
45
	}
46
47
	/**
48
	 * @param string $dataTypeId
49
	 *
50
	 * @return DataValueHandler
51
	 * @throws OutOfBoundsException
52
	 */
53
	public function getQualifierHandler( $dataTypeId ) {
54
		if ( !array_key_exists( $dataTypeId, $this->qualifierHandlers ) ) {
55
			throw new OutOfBoundsException( "There is no qualifier DataValueHandler for '$dataTypeId'." );
56
		}
57
58
		return $this->qualifierHandlers[$dataTypeId];
59
	}
60
61
	/**
62
	 * @return DataValueHandler[]
63
	 */
64
	public function getMainSnakHandlers() {
65
		return $this->mainSnakHandlers;
66
	}
67
68
	/**
69
	 * @return DataValueHandler[]
70
	 */
71
	public function getQualifierHandlers() {
72
		return $this->qualifierHandlers;
73
	}
74
75
}
76