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

StatementSetter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 46
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Addwiki\Wikibase\Api\Service;
4
5
use Addwiki\Mediawiki\DataModel\EditInfo;
6
use Addwiki\Wikibase\Api\WikibaseApi;
7
use InvalidArgumentException;
8
use Serializers\Serializer;
9
use Wikibase\DataModel\Statement\Statement;
10
11
/**
12
 * @access private
13
 *
14
 * @author Addshore
15
 */
16
class StatementSetter {
17
18
	private WikibaseApi $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...
19
20
	private \Serializers\Serializer $statementSerializer;
21
22
	/**
23
	 * @param WikibaseApi $api
24
	 * @param Serializer $statementSerializer
25
	 */
26
	public function __construct( WikibaseApi $api, Serializer $statementSerializer ) {
27
		$this->api = $api;
28
		$this->statementSerializer = $statementSerializer;
29
	}
30
31
	/**
32
	 * @since 0.5
33
	 *
34
	 * @param Statement $statement
35
	 * @param EditInfo|null $editInfo
36
	 *
37
	 * @throws InvalidArgumentException
38
	 *
39
	 * @todo allow setting of indexes
40
	 */
41
	public function set( Statement $statement, EditInfo $editInfo = null ): bool {
42
		if ( $statement->getGuid() === null ) {
43
			throw new InvalidArgumentException( 'Can not set a statement that does not have a GUID' );
44
		}
45
46
		$params = [
47
			'claim' => json_encode( $this->statementSerializer->serialize( $statement ) ),
48
		];
49
50
		$this->api->postRequest( 'wbsetclaim', $params, $editInfo );
51
		return true;
52
	}
53
54
}
55