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

StatementRemover::remove()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 21

Duplication

Lines 9
Ratio 42.86 %

Importance

Changes 0
Metric Value
dl 9
loc 21
rs 9.2728
c 0
b 0
f 0
cc 5
nc 7
nop 2
1
<?php
2
3
namespace Addwiki\Wikibase\Api\Service;
4
5
use Addwiki\Mediawiki\DataModel\EditInfo;
6
use Addwiki\Wikibase\Api\WikibaseApi;
7
use UnexpectedValueException;
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
	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
	/**
21
	 * @param WikibaseApi $api
22
	 */
23
	public function __construct( WikibaseApi $api ) {
24
		$this->api = $api;
25
	}
26
27
	/**
28
	 * @since 0.2
29
	 *
30
	 * @param Statement|StatementGuid|string $statement Statement object or GUID
31
	 * @param EditInfo|null $editInfo
32
	 *
33
	 * @throws UnexpectedValueException
34
	 */
35
	public function remove( $statement, EditInfo $editInfo = null ): bool {
36
		if ( is_string( $statement ) ) {
37
			$guid = $statement;
38
		} elseif ( $statement instanceof StatementGuid ) {
39
			$guid = $statement->getSerialization();
40
		} elseif ( $statement instanceof Statement ) {
41
			$guid = $statement->getGuid();
42
		} else {
43
			throw new UnexpectedValueException( 'Could not get statement guid from $statement' );
44
		}
45
		if ( !is_string( $guid ) ) {
46
			throw new UnexpectedValueException( 'Unexpected statement guid got from $statement' );
47
		}
48
49
		$params = [
50
			'claim' => $guid,
51
		];
52
53
		$this->api->postRequest( 'wbremoveclaims', $params, $editInfo );
54
		return true;
55
	}
56
57
}
58