Completed
Push — main ( b55b92...e8d442 )
by
unknown
05:41
created

WikibaseApi   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 48
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Addwiki\Wikibase\Api;
4
5
use Addwiki\Mediawiki\Api\Client\MediawikiApi;
6
use Addwiki\Mediawiki\Api\Client\SimpleRequest;
7
use Addwiki\Mediawiki\DataModel\EditInfo;
8
9
/**
10
 * @access private
11
 *
12
 * @author Bene* < [email protected] >
13
 */
14
class WikibaseApi {
15
16
	private MediawikiApi $api;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
17
18
	public function __construct( MediawikiApi $api ) {
19
		$this->api = $api;
20
	}
21
22
	/**
23
	 * @param EditInfo|null $editInfo
24
	 *
25
	 * @return mixed
26
	 */
27
	public function postRequest( string $action, array $params, EditInfo $editInfo = null ) {
28
		if ( $editInfo !== null ) {
29
			$params = array_merge( $this->getEditInfoParams( $editInfo ), $params );
30
		}
31
32
		$params['token'] = $this->api->getToken();
33
		return $this->api->postRequest( new SimpleRequest( $action, $params ) );
34
	}
35
36
	private function getEditInfoParams( EditInfo $editInfo ): array {
37
		$params = [];
38
39
		if ( $editInfo->getSummary() !== '' ) {
40
			$params['summary'] = $editInfo->getSummary();
41
		}
42
		if ( $editInfo->getMinor() ) {
43
			$params['minor'] = true;
44
		}
45
		if ( $editInfo->getBot() ) {
46
			$params['bot'] = true;
47
			$params['assert'] = 'bot';
48
		}
49
		if ( $editInfo->getMaxlag() ) {
50
			$params['maxlag'] = $editInfo->getMaxlag();
51
		}
52
53
		return $params;
54
	}
55
56
}
57