StatementGetter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0
ccs 0
cts 10
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFromGuid() 0 11 1
1
<?php
2
3
namespace Wikibase\Api\Service;
4
5
use Deserializers\Deserializer;
6
use Mediawiki\Api\MediawikiApi;
7
use Mediawiki\Api\SimpleRequest;
8
use Wikibase\DataModel\Statement\Statement;
9
10
/**
11
 * @access private
12
 *
13
 * @author Addshore
14
 */
15
class StatementGetter {
16
17
	/**
18
	 * @var MediawikiApi
19
	 */
20
	private $api;
21
22
	/**
23
	 * @var Deserializer
24
	 */
25
	private $statementDeserializer;
26
27
	/**
28
	 * @param MediawikiApi $api
29
	 * @param Deserializer $statementDeserializer
30
	 */
31
	public function __construct( MediawikiApi $api, Deserializer $statementDeserializer ) {
32
		$this->api = $api;
33
		$this->statementDeserializer = $statementDeserializer;
34
	}
35
36
	/**
37
	 * @param string $guid
38
	 *
39
	 * @return Statement
40
	 */
41
	public function getFromGuid( $guid ) {
42
		$params = [
43
			'claim' => $guid,
44
		];
45
46
		$result = $this->api->getRequest( new SimpleRequest( 'wbgetclaims', $params ) );
47
48
		$statementSerialization = array_shift( array_shift( $result['claims'] ) );
0 ignored issues
show
Bug introduced by
array_shift($result['claims']) cannot be passed to array_shift() as the parameter $array expects a reference.
Loading history...
49
50
		return $this->statementDeserializer->deserialize( $statementSerialization );
51
	}
52
53
}
54