DataType   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 0
dl 0
loc 84
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 12 5
A getId() 0 3 1
A getDataValueType() 0 3 1
A getMessageKey() 0 3 1
A toArray() 0 5 1
1
<?php
2
3
namespace DataTypes;
4
5
use InvalidArgumentException;
6
7
/**
8
 * @since 0.1
9
 *
10
 * @license GPL-2.0+
11
 * @author Jeroen De Dauw < [email protected] >
12
 * @author Thiemo Mättig
13
 */
14
class DataType {
15
16
	/**
17
	 * Identifier of this data type (also referred to as "property type").
18
	 *
19
	 * @since 0.1
20
	 *
21
	 * @var string
22
	 */
23
	protected $typeId;
24
25
	/**
26
	 * Identifier for the type of the DataValue.
27
	 *
28
	 * @since 0.1
29
	 *
30
	 * @var string
31
	 */
32
	protected $dataValueType;
33
34
	/**
35
	 * @since 0.5
36
	 *
37
	 * @param string $typeId Identifier of this data type (also referred to as "property type").
38
	 * @param string $dataValueType Identifier for the type of the DataValue.
39
	 *
40
	 * @throws InvalidArgumentException
41
	 */
42
	public function __construct( $typeId, $dataValueType ) {
43
		if ( !is_string( $typeId ) || $typeId === '' ) {
44
			throw new InvalidArgumentException( '$typeId must be a non-empty string' );
45
		}
46
47
		if ( !is_string( $dataValueType ) || $dataValueType === '' ) {
48
			throw new InvalidArgumentException( '$dataValueType must be a non-empty string' );
49
		}
50
51
		$this->typeId = $typeId;
52
		$this->dataValueType = $dataValueType;
53
	}
54
55
	/**
56
	 * Returns the identifier of this data type (also referred to as "property type").
57
	 *
58
	 * @since 0.1
59
	 *
60
	 * @return string
61
	 */
62
	public function getId() {
63
		return $this->typeId;
64
	}
65
66
	/**
67
	 * Returns the type of the DataValue used by this data type.
68
	 *
69
	 * @since 0.1
70
	 *
71
	 * @return string
72
	 */
73
	public function getDataValueType() {
74
		return $this->dataValueType;
75
	}
76
77
	/**
78
	 * @since 1.0
79
	 *
80
	 * @return string
81
	 */
82
	public function getMessageKey() {
83
		return 'datatypes-type-' . $this->typeId;
84
	}
85
86
	/**
87
	 * @since 0.1
88
	 *
89
	 * @return string[]
90
	 */
91
	public function toArray() {
92
		return [
93
			'dataValueType' => $this->dataValueType
94
		];
95
	}
96
97
}
98