StatementSetter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 46
rs 10
c 0
b 0
f 0
ccs 0
cts 11
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set() 0 12 2
1
<?php
2
3
namespace Wikibase\Api\Service;
4
5
use InvalidArgumentException;
6
use Mediawiki\DataModel\EditInfo;
7
use Serializers\Serializer;
8
use Wikibase\Api\WikibaseApi;
9
use Wikibase\DataModel\Statement\Statement;
10
11
/**
12
 * @access private
13
 *
14
 * @author Addshore
15
 */
16
class StatementSetter {
17
18
	/**
19
	 * @var WikibaseApi
20
	 */
21
	private $api;
22
23
	/**
24
	 * @var Serializer
25
	 */
26
	private $statementSerializer;
27
28
	/**
29
	 * @param WikibaseApi $api
30
	 * @param Serializer $statementSerializer
31
	 */
32
	public function __construct( WikibaseApi $api, Serializer $statementSerializer ) {
33
		$this->api = $api;
34
		$this->statementSerializer = $statementSerializer;
35
	}
36
37
	/**
38
	 * @since 0.5
39
	 *
40
	 * @param Statement $statement
41
	 * @param EditInfo|null $editInfo
42
	 *
43
	 * @throws InvalidArgumentException
44
	 * @return bool
45
	 *
46
	 * @todo allow setting of indexes
47
	 */
48
	public function set( Statement $statement, EditInfo $editInfo = null ) {
49
		if( $statement->getGuid() === null ) {
50
			throw new InvalidArgumentException( 'Can not set a statement that does not have a GUID' );
51
		}
52
53
		$params = array(
54
			'claim' => json_encode( $this->statementSerializer->serialize( $statement ) ),
55
		);
56
57
		$this->api->postRequest( 'wbsetclaim', $params, $editInfo );
58
		return true;
59
	}
60
61
} 
62