Completed
Push — detect-covers-fails ( bd35c8...c3f051 )
by no
16:27 queued 12:25
created

BasicEntityIdParser::getBuilders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Entity;
4
5
/**
6
 * Object that can parse the serializations of the EntityIds defined by the DataModel.
7
 *
8
 * @since 4.2
9
 *
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class BasicEntityIdParser implements EntityIdParser {
14
15
	private $idParser;
16
17
	public function __construct() {
18
		$this->idParser = new DispatchingEntityIdParser( self::getBuilders() );
19
	}
20
21
	/**
22
	 * @param string $idSerialization
23
	 *
24
	 * @return ItemId|PropertyId
25
	 * @throws EntityIdParsingException
26
	 */
27
	public function parse( $idSerialization ) {
28
		return $this->idParser->parse( $idSerialization );
29
	}
30
31
	/**
32
	 * Returns an id builders array.
33
	 * Keys are preg_match patterns, values are callables.
34
	 * (See the DispatchingEntityIdParser constructor for more details.)
35
	 *
36
	 * This method returns builders for the ids of all entity types
37
	 * defined by WikibaseDataModel. It is intended to be used by
38
	 * applications that allow for registration of additional entity
39
	 * types, and thus want to extend upon this list. The extended
40
	 * list can then be used to construct a DispatchingEntityIdParser instance.
41
	 *
42
	 * @return callable[]
43
	 */
44
	public static function getBuilders() {
45
		return array(
46
			ItemId::PATTERN => function( $serialization ) {
47
				return new ItemId( $serialization );
48
			},
49
			PropertyId::PATTERN => function( $serialization ) {
50
				return new PropertyId( $serialization );
51
			},
52
		);
53
	}
54
55
}
56