StatementGetter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 1
nc 1
nop 2
crap 2
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 = array(
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 addshore
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
}