Completed
Push — master ( 11966d...5d848f )
by Sam
13s
created

UserBlocker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Mediawiki\Api\Service;
4
5
use InvalidArgumentException;
6
use Mediawiki\Api\SimpleRequest;
7
use Mediawiki\DataModel\User;
8
9
/**
10
 * @access private
11
 *
12
 * @author Addshore
13
 */
14
class UserBlocker extends Service {
15
16
	/**
17
	 * @since 0.3
18
	 *
19
	 * @param User|string $user
20
	 * @param array $extraParams
21
	 *
22
	 * @throws InvalidArgumentException
23
	 * @return bool
24
	 */
25
	public function block( $user, array $extraParams = [] ) {
26
		if ( !$user instanceof User && !is_string( $user ) ) {
27
			throw new InvalidArgumentException( '$user must be either a string or User object' );
28
		}
29
30
		if ( $user instanceof User ) {
31
			$user = $user->getName();
32
		}
33
34
		$params = [
35
			'user' => $user,
36
			'token' => $this->api->getToken( 'block' ),
37
		];
38
39
		$params = array_merge( $extraParams, $params );
40
41
		$this->api->postRequest( new SimpleRequest( 'block', $params ) );
42
		return true;
43
	}
44
45
}
46