UserGetter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 51
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFromUsername() 0 13 1
A newUserFromListUsersResult() 0 23 2
1
<?php
2
3
namespace Mediawiki\Api\Service;
4
5
use Mediawiki\Api\SimpleRequest;
6
use Mediawiki\DataModel\User;
7
8
/**
9
 * @access private
10
 *
11
 * @author Addshore
12
 */
13
class UserGetter extends Service {
14
15
	/**
16
	 * @param string $username
17
	 *
18
	 * @return User
19
	 */
20
	public function getFromUsername( $username ) {
21
		$result = $this->api->getRequest(
22
			new SimpleRequest(
23
				'query', [
24
				'list' => 'users',
25
				'ususers' => $username,
26
				'usprop' => 'gender|emailable|registration|editcount|rights|implicitgroups|groups|blockinfo',
27
			]
28
			)
29
		);
30
31
		return $this->newUserFromListUsersResult( array_shift( $result['query']['users'] ) );
32
	}
33
34
	/**
35
	 * @param array $array
36
	 *
37
	 * @return User
38
	 */
39
	private function newUserFromListUsersResult( $array ) {
40
		if ( array_key_exists( 'userid', $array ) ) {
41
			return new User(
42
				$array['name'],
43
				$array['userid'],
44
				$array['editcount'],
45
				$array['registration'],
46
				[ 'groups' => $array['groups'], 'implicitgroups' => $array['implicitgroups'] ],
47
				$array['rights'],
48
				$array['gender']
49
			);
50
		} else {
51
			return new User(
52
				$array['name'],
53
				0,
54
				0,
55
				'',
56
				[ 'groups' => [], 'implicitgroups' => [] ],
57
				[],
58
				''
59
			);
60
		}
61
	}
62
63
}
64