These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
|
|||
41 | $guid = $statement; |
||
42 | } elseif ( $statement instanceof StatementGuid ) { |
||
43 | $guid = $statement->getSerialization(); |
||
0 ignored issues
–
show
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 |
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.