PageIdentifier   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 96.43%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 0
loc 78
ccs 27
cts 28
cp 0.9643
rs 10
c 0
b 0
f 0

6 Methods

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