Reference::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Samwilson\SimpleWikidata;
4
5
use Psr\Cache\CacheItemPoolInterface;
6
7
class Reference {
8
9
	const STATED_IN = 'P248';
10
11
	/** @var array */
12
	protected $data;
13
14
	/** @var string */
15
	protected $lang;
16
17
	/** @var CacheItemPoolInterface */
18
	protected $cache;
19
20
	/**
21
	 * @param string[] $data The data.
22
	 * @param string $lang ISO639 language code.
23
	 * @param CacheItemPoolInterface $cache The cache.
24
	 */
25
	public function __construct( $data, $lang, $cache ) {
26
		$this->data = $data;
27
		$this->lang = $lang;
28
		$this->cache = $cache;
29
	}
30
31
	/**
32
	 * @return Item|bool The item, or false if there isn't one.
33
	 */
34
	public function statedIn() {
35
		if ( !isset( $this->data['snaks'][self::STATED_IN] ) ) {
36
			return false;
37
		}
38
		foreach ( $this->data['snaks'][self::STATED_IN] as $snak ) {
39
			return Item::factory( $snak['datavalue']['value']['id'], $this->lang, $this->cache );
40
		}
41
	}
42
}
43