Completed
Push — main ( 2daa48...b5d932 )
by
unknown
08:38
created

UserRightsChanger   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 44
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 0 33 3
1
<?php
2
3
namespace Addwiki\Mediawiki\Api\Service;
4
5
use Addwiki\Mediawiki\Api\Client\SimpleRequest;
6
use Addwiki\Mediawiki\DataModel\User;
7
8
/**
9
 * @access private
10
 *
11
 * @author Addshore
12
 */
13
class UserRightsChanger extends Service {
14
15
	/**
16
	 * @since 0.3
17
	 *
18
	 * @param string[] $add
19
	 * @param string[] $remove
20
	 *
21
	 */
22
	public function change(
23
		User $user,
24
		array $add = [],
25
		array $remove = [],
26
		array $extraParams = []
27
	): bool {
28
		$result = $this->api->postRequest(
29
			new SimpleRequest(
30
				'query', [
31
				'list' => 'users',
32
				'ustoken' => 'userrights',
33
				'ususers' => $user->getName(),
34
			]
35
			)
36
		);
37
38
		$params = [
39
			'user' => $user->getName(),
40
			'token' => $result['query']['users'][0]['userrightstoken'],
41
		];
42
		if ( !empty( $add ) ) {
43
			$params['add'] = implode( '|', $add );
44
		}
45
		if ( !empty( $remove ) ) {
46
			$params['remove'] = implode( '|', $remove );
47
		}
48
49
		$this->api->postRequest(
50
			new SimpleRequest( 'userrights', array_merge( $extraParams, $params ) )
51
		);
52
53
		return true;
54
	}
55
56
}
57