UserBlocker::block()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 15
cp 0
rs 9.6333
c 0
b 0
f 0
cc 4
nc 3
nop 2
crap 20
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