Completed
Push — main ( 1f6f71...689fbc )
by
unknown
04:30
created

User::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Addwiki\Mediawiki\DataModel;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Represents a mediawiki user
9
 *
10
 * @author Addshore
11
 */
12
class User {
13
14
	/**
15
	 * @var string
16
	 */
17
	private $name;
18
19
	/**
20
	 * @var int
21
	 */
22
	private $id;
23
24
	/**
25
	 * @var int
26
	 */
27
	private $editcount;
28
29
	/**
30
	 * @var string
31
	 */
32
	private $registration;
33
34
	/**
35
	 * @var array
36
	 */
37
	private $groups = [];
38
39
	/**
40
	 * @var array
41
	 */
42
	private $rights = [];
43
44
	/**
45
	 * @var string
46
	 */
47
	private $gender;
48
49
	/**
50
	 * @param string $name
51
	 * @param int $id
52
	 * @param int $editcount
53
	 * @param string $registration
54
	 * @param array[] $groups groups grouped by type.
55
	 *                              Keys to use are
56
	 *                              'groups' and
57
	 *                              'implicitgroups' as
58
	 *                              returned by the api.
59
	 * @param array $rights
60
	 * @param string $gender
61
	 *
62
	 * @throws InvalidArgumentException
63
	 */
64
	public function __construct( $name, $id, $editcount, $registration, $groups, $rights, $gender ) {
65
		if ( !is_string( $name ) || empty( $name ) ) {
66
			throw new InvalidArgumentException( '$name must be a string and can not be empty' );
67
		}
68
		if ( !is_int( $id ) ) {
69
			throw new InvalidArgumentException( '$id must be an int' );
70
		}
71
		if ( !is_int( $editcount ) ) {
72
			throw new InvalidArgumentException( '$editcount must be an int' );
73
		}
74
		if ( !is_array( $groups ) || !array_key_exists( 'groups', $groups ) || !array_key_exists( 'implicitgroups', $groups ) ) {
75
			throw new InvalidArgumentException( '$groups must be an array or arrays with keys "groups" and "implicitgroups"' );
76
		}
77
		if ( !is_array( $rights ) ) {
78
			throw new InvalidArgumentException( '$rights must be an array' );
79
		}
80
		if ( !is_string( $gender ) ) {
81
			throw new InvalidArgumentException( '$gender must be a string' );
82
		}
83
84
		$this->editcount = $editcount;
85
		$this->gender = $gender;
86
		$this->groups = $groups;
87
		$this->id = $id;
88
		$this->name = $name;
89
		$this->registration = $registration;
90
		$this->rights = $rights;
91
	}
92
93
	/**
94
	 * @return int
95
	 */
96
	public function getEditcount() {
97
		return $this->editcount;
98
	}
99
100
	/**
101
	 * @return string
102
	 */
103
	public function getGender() {
104
		return $this->gender;
105
	}
106
107
	/**
108
	 * @param string $type 'groups' or 'implicitgroups'
109
	 *
110
	 * @return array
111
	 */
112
	public function getGroups( $type = 'groups' ) {
113
		return $this->groups[$type];
114
	}
115
116
	/**
117
	 * @return int
118
	 */
119
	public function getId() {
120
		return $this->id;
121
	}
122
123
	/**
124
	 * @return string
125
	 */
126
	public function getName() {
127
		return $this->name;
128
	}
129
130
	/**
131
	 * @return string
132
	 */
133
	public function getRegistration() {
134
		return $this->registration;
135
	}
136
137
	/**
138
	 * @return array
139
	 */
140
	public function getRights() {
141
		return $this->rights;
142
	}
143
144
}
145