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\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
|
|||
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 | } |
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.