Completed
Push — master ( 2a3272...f39d74 )
by Thomas
08:55
created

newWikibaseEntityParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 2
1
<?php
2
3
namespace PPP\Wikidata\ValueParsers;
4
5
use DataValues\Geo\Parsers\GlobeCoordinateParser;
6
use ValueParsers\ParserOptions;
7
use ValueParsers\ValueParser;
8
use Wikibase\EntityStore\EntityStore;
9
10
/**
11
 * Build a parser for Wikibase value
12
 *
13
 * @licence GPLv2+
14
 * @author Thomas Pellissier Tanon
15
 */
16
class WikibaseValueParserFactory {
17
18
	/**
19
	 * @var string language code
20
	 */
21
	private $languageCode;
22
23
	/**
24
	 * @var EntityStore
25
	 */
26
	private $entityStore;
27
28
	/**
29
	 * @param $languageCode
30
	 * @param EntityStore $entityStore
31
	 */
32 8
	public function __construct($languageCode, EntityStore $entityStore) {
33 8
		$this->languageCode = $languageCode;
34 8
		$this->entityStore = $entityStore;
35
	}
36
37
	/**
38
	 * @return WikibaseValueParser
39
	 */
40 8
	public function newWikibaseValueParser() {
41
		return new WikibaseValueParser(array(
42
			'commonsMedia' => new StringParser(),
43
			'external-id' => new StringParser(),
44
			'globe-coordinate' => new GlobeCoordinateParser(),
45
			//TODO 'quantity' => ,
46
			'monolingualtext' => new MonolingualTextParser(),
47
			'string' => new StringParser(),
48
			//TODO 'time' => ,
49
			'url' => new StringParser(),
50 8
			'wikibase-item' => $this->newWikibaseEntityParser('item'),
51 8
			'wikibase-property' => $this->newWikibaseEntityParser('property')
52
		));
53
	}
54
55
	private function newWikibaseEntityParser($type) {
56
		$parserOptions = new ParserOptions(array(
57
			ValueParser::OPT_LANG => $this->languageCode,
58
			WikibaseEntityIdParser::OPT_ENTITY_TYPE => $type
59
		));
60
61
		return new WikibaseEntityIdParser(
62
			$this->entityStore,
63
			$parserOptions
64
		);
65
	}
66
}
67