MediaWikiTitleValue   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 31.25%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 93
ccs 5
cts 16
cp 0.3125
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A serialize() 0 3 1
A unserialize() 0 3 1
A getType() 0 3 1
A getSortKey() 0 3 1
A getValue() 0 3 1
A newFromArray() 0 3 1
1
<?php
2
3
namespace ParamProcessor;
4
5
use DataValues\DataValueObject;
6
use InvalidArgumentException;
7
use Title;
8
9
/**
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class MediaWikiTitleValue extends DataValueObject {
14
15
	/**
16
	 * @since 0.1
17
	 *
18
	 * @var Title
19
	 */
20
	protected $title;
21
22
	/**
23
	 * @since 0.1
24
	 *
25
	 * @param Title $title
26
	 *
27
	 * @throws InvalidArgumentException
28
	 */
29 9
	public function __construct( Title $title ) {
30 9
		$this->title = $title;
31 9
	}
32
33
	/**
34
	 * @see Serializable::serialize
35
	 *
36
	 * @since 0.1
37
	 *
38
	 * @return string
39
	 */
40
	public function serialize() {
41
		return $this->title->getFullText();
42
	}
43
44
	/**
45
	 * @see Serializable::unserialize
46
	 *
47
	 * @since 0.1
48
	 *
49
	 * @param string $value
50
	 *
51
	 * @return MediaWikiTitleValue
52
	 */
53
	public function unserialize( $value ) {
54
		$this->__construct( Title::newFromText( $value ) );
55
	}
56
57
	/**
58
	 * @see DataValue::getType
59
	 *
60
	 * @since 0.1
61
	 *
62
	 * @return string
63
	 */
64
	public static function getType() {
65
		return 'mediawikititle';
66
	}
67
68
	/**
69
	 * @see DataValue::getSortKey
70
	 *
71
	 * @since 0.1
72
	 *
73
	 * @return string|float|int
74
	 */
75
	public function getSortKey() {
76
		return $this->title->getCategorySortkey();
77
	}
78
79
	/**
80
	 * Returns the Title object.
81
	 * @see DataValue::getValue
82
	 *
83
	 * @since 0.1
84
	 *
85
	 * @return Title
86
	 */
87 7
	public function getValue() {
88 7
		return $this->title;
89
	}
90
91
	/**
92
	 * Constructs a new instance of the DataValue from the provided data.
93
	 * This can round-trip with @see getArrayValue
94
	 *
95
	 * @since 0.1
96
	 *
97
	 * @param mixed $data
98
	 *
99
	 * @return MediaWikiTitleValue
100
	 */
101
	public static function newFromArray( $data ) {
102
		return new static( $data );
103
	}
104
105
}