Completed
Push — master ( d9d8d8...938f0a )
by Thomas
06:02 queued 03:18
created

WikibaseValueParserFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 3
c 4
b 0
f 2
lcom 1
cbo 6
dl 0
loc 51
ccs 23
cts 23
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A newWikibaseValueParser() 0 14 1
A newWikibaseEntityParser() 0 11 1
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 8
	}
36
37
	/**
38
	 * @return WikibaseValueParser
39
	 */
40 8
	public function newWikibaseValueParser() {
41 8
		return new WikibaseValueParser(array(
42 8
			'commonsMedia' => new StringParser(),
43 8
			'external-id' => new StringParser(),
44 8
			'globe-coordinate' => new GlobeCoordinateParser(),
45
			//TODO 'quantity' => ,
46 8
			'monolingualtext' => new MonolingualTextParser(),
47 8
			'string' => new StringParser(),
48
			//TODO 'time' => ,
49 8
			'url' => new StringParser(),
50 8
			'wikibase-item' => $this->newWikibaseEntityParser('item'),
51 8
			'wikibase-property' => $this->newWikibaseEntityParser('property')
52 8
		));
53
	}
54
55 8
	private function newWikibaseEntityParser($type) {
56 8
		$parserOptions = new ParserOptions(array(
57 8
			ValueParser::OPT_LANG => $this->languageCode,
58 8
			WikibaseEntityIdParser::OPT_ENTITY_TYPE => $type
59 8
		));
60
61 8
		return new WikibaseEntityIdParser(
62 8
			$this->entityStore,
63
			$parserOptions
64 8
		);
65
	}
66
}
67