ReferenceRemover   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 55
rs 10
c 0
b 0
f 0
ccs 0
cts 24
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B set() 0 29 7
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\Reference;
9
use Wikibase\DataModel\Statement\Statement;
10
use Wikibase\DataModel\Statement\StatementGuid;
11
12
/**
13
 * @access private
14
 *
15
 * @author Addshore
16
 */
17
class ReferenceRemover {
18
19
	/**
20
	 * @var WikibaseApi
21
	 */
22
	private $api;
23
24
	/**
25
	 * @param WikibaseApi $api
26
	 */
27
	public function __construct( WikibaseApi $api ) {
28
		$this->api = $api;
29
	}
30
31
	/**
32
	 * @since 0.2
33
	 *
34
	 * @param Reference|string $reference Reference object or hash
35
	 * @param Statement|StatementGuid|string $target Statement object or GUID
36
	 * @param EditInfo|null $editInfo
37
	 *
38
	 * @throws UnexpectedValueException
39
	 * @return bool
40
	 */
41
	public function set( $reference, $target, EditInfo $editInfo = null ) {
42
		if( $reference instanceof Reference ) {
43
			$reference = $reference->getHash();
44
		}
45
		if( !is_string( $reference ) ) {
46
			throw new UnexpectedValueException( 'Could not get reference hash from $reference' );
47
		}
48
49
		if( is_string( $target ) ) {
50
			$guid = $target;
51
		} else if ( $target instanceof StatementGuid ) {
52
			$guid = $target->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...
53
		} else if ( $target instanceof Statement ) {
54
			$guid = $target->getGuid();
55
		} else {
56
			throw new UnexpectedValueException( 'Could not get statement guid from $target' );
57
		}
58
		if( !is_string( $guid ) ) {
59
			throw new UnexpectedValueException( 'Unexpected statement guid got from $target' );
60
		}
61
62
		$params = array(
63
			'statement' => $guid,
64
			'references' => $reference,
65
		);
66
67
		$this->api->postRequest( 'wbremovereferences', $params, $editInfo );
68
		return true;
69
	}
70
71
}