StatementRemover   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A remove() 0 21 5
1
<?php
2
3
namespace Wikibase\Api\Service;
4
5
use Mediawiki\DataModel\EditInfo;
6
use UnexpectedValueException;
7
use Wikibase\Api\WikibaseApi;
8
use Wikibase\DataModel\Statement\Statement;
9
use Wikibase\DataModel\Statement\StatementGuid;
10
11
/**
12
 * @access private
13
 *
14
 * @author Addshore
15
 */
16
class StatementRemover {
17
18
	/**
19
	 * @var WikibaseApi
20
	 */
21
	private $api;
22
23
	/**
24
	 * @param WikibaseApi $api
25
	 */
26
	public function __construct( WikibaseApi $api ) {
27
		$this->api = $api;
28
	}
29
30
	/**
31
	 * @since 0.2
32
	 *
33
	 * @param Statement|StatementGuid|string $statement Statement object or GUID
34
	 * @param EditInfo|null $editInfo
35
	 *
36
	 * @return bool
37
	 * @throws UnexpectedValueException
38
	 */
39
	public function remove( $statement, EditInfo $editInfo = null ) {
40
		if( is_string( $statement ) ) {
41
			$guid = $statement;
42
		} else if ( $statement instanceof StatementGuid ) {
43
			$guid = $statement->getSerialization();
0 ignored issues
show
Deprecated Code introduced by addshore
The method Wikibase\DataModel\State...uid::getSerialization() has been deprecated with message: The value returned by this method might differ in case from the original, unparsed statement GUID
(the entity ID part might have been lowercase originally, but is always normalized in the return value here),
which means that the value should not be compared to other statement GUID serializations,
e.g. to look up a statement in a StatementList.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
44
		} else if ( $statement instanceof Statement ) {
45
			$guid = $statement->getGuid();
46
		} else {
47
			throw new UnexpectedValueException( 'Could not get statement guid from $statement' );
48
		}
49
		if( !is_string( $guid ) ) {
50
			throw new UnexpectedValueException( 'Unexpected statement guid got from $statement' );
51
		}
52
53
		$params = array(
54
			'claim' => $guid,
55
		);
56
57
		$this->api->postRequest( 'wbremoveclaims', $params, $editInfo );
58
		return true;
59
	}
60
61
}