WikibaseApi::postRequest()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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