Title   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 73
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A getNs() 0 3 1
A getText() 0 3 1
A getTitle() 0 3 1
A jsonDeserialize() 0 3 1
A jsonSerialize() 0 6 1
1
<?php
2
3
namespace Mediawiki\DataModel;
4
5
use InvalidArgumentException;
6
use JsonSerializable;
7
8
/**
9
 * @author Addshore
10
 */
11
class Title implements JsonSerializable {
12
13
	/**
14
	 * @var string
15
	 */
16
	private $title;
17
18
	/**
19
	 * @var int
20
	 */
21
	private $ns;
22
23
	/**
24
	 * @param string $title
25
	 * @param int $ns
26
	 *
27
	 * @throws InvalidArgumentException
28
	 */
29 10
	public function __construct( $title, $ns = 0 ) {
30 10
		if ( !is_string( $title ) ) {
31 4
			throw new InvalidArgumentException( '$title must be a string' );
32
		}
33 6
		if ( !is_int( $ns ) ) {
34 2
			throw new InvalidArgumentException( '$ns must be an int' );
35
		}
36 4
		$this->title = $title;
37 4
		$this->ns = $ns;
38 4
	}
39
40
	/**
41
	 * @return int
42
	 * @since 0.1
43
	 */
44 3
	public function getNs() {
45 3
		return $this->ns;
46
	}
47
48
	/**
49
	 * @return string
50
	 * @since 0.6
51
	 */
52 3
	public function getText() {
53 3
		return $this->title;
54
	}
55
56
	/**
57
	 * @return string
58
	 * @deprecated in 0.6 use getText (makes things look cleaner)
59
	 */
60 3
	public function getTitle() {
61 3
		return $this->getText();
62
	}
63
64
	/**
65
	 * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
66
	 */
67 1
	public function jsonSerialize() {
68
		return [
69 1
		'title' => $this->title,
70 1
		'ns' => $this->ns,
71 1
		];
72
	}
73
74
	/**
75
	 * @param array $json
76
	 *
77
	 * @return self
78
	 */
79 1
	public static function jsonDeserialize( $json ) {
80 1
		return new self( $json['title'], $json['ns'] );
81
	}
82
83
}
84