StatementRemover   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 19.57 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A remove() 9 21 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
		if ( is_string( $statement ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
			$guid = $statement;
42
		} elseif ( $statement instanceof StatementGuid ) {
43
			$guid = $statement->getSerialization();
0 ignored issues
show
Deprecated Code introduced by
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
		} elseif ( $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 = [
54
			'claim' => $guid,
55
		];
56
57
		$this->api->postRequest( 'wbremoveclaims', $params, $editInfo );
58
		return true;
59
	}
60
61
}
62