WikibaseApi   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 45
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A postRequest() 0 8 2
A getEditInfoParams() 0 16 4
1
<?php
2
3
4
namespace Wikibase\Api;
5
6
use Mediawiki\Api\MediawikiApi;
7
use Mediawiki\Api\SimpleRequest;
8
use Mediawiki\DataModel\EditInfo;
9
10
/**
11
 * @access private
12
 *
13
 * @author Bene* < [email protected] >
14
 */
15
class WikibaseApi {
16
17
	/**
18
	 * @var MediawikiApi $api
19
	 */
20
	private $api;
21
22
	public function __construct( MediawikiApi $api ) {
23
		$this->api = $api;
24
	}
25
26
	/**
27
	 * @param string $action
28
	 * @param array $params
29
	 * @param EditInfo|null $editInfo
30
	 *
31
	 * @return mixed
32
	 */
33
	public function postRequest( $action, array $params, EditInfo $editInfo = null ) {
34
		if ( $editInfo !== null ) {
35
			$params = array_merge( $this->getEditInfoParams( $editInfo ), $params );
36
		}
37
38
		$params['token'] = $this->api->getToken();
39
		return $this->api->postRequest( new SimpleRequest( $action, $params ) );
40
	}
41
42
	private function getEditInfoParams( EditInfo $editInfo ) {
43
		$params = array();
44
45
		if ( $editInfo->getSummary() ) {
46
			$params['summary'] = $editInfo->getSummary();
47
		}
48
		if ( $editInfo->getMinor() ) {
49
			$params['minor'] = true;
50
		}
51
		if ( $editInfo->getBot() ) {
52
			$params['bot'] = true;
53
			$params['assert'] = 'bot';
54
		}
55
56
		return $params;
57
	}
58
59
}
60