Completed
Push — master ( 668785...5742ff )
by
unknown
02:36
created

WikibaseServices::getService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace WikibaseQuality\ConstraintReport;
4
5
use MediaWiki\MediaWikiServices;
6
use Wikibase\DataModel\Services\Lookup\EntityLookup;
7
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
8
9
/**
10
 * These services should really be registered by Wikibase,
11
 * but Wikibase doesn’t register them yet
12
 * and we need them to be registered as services for some tests,
13
 * so for now we register them on Wikibase’ behalf.
14
 *
15
 * @license GPL-2.0-or-later
16
 */
17
class WikibaseServices {
18
19
	const ENTITY_LOOKUP = 'WBQC_EntityLookup';
20
	const PROPERTY_DATA_TYPE_LOOKUP = 'WBQC_PropertyDataTypeLookup';
21
22
	private static function getService( MediaWikiServices $services = null, $name ) {
23
		if ( $services === null ) {
24
			$services = MediaWikiServices::getInstance();
25
		}
26
		return $services->getService( $name );
27
	}
28
29
	/**
30
	 * @param MediaWikiServices|null $services
31
	 * @return EntityLookup
32
	 */
33
	public static function getEntityLookup( MediaWikiServices $services = null ) {
34
		return self::getService( $services, self::ENTITY_LOOKUP );
35
	}
36
37
	/**
38
	 * @param MediaWikiServices|null $services
39
	 * @return PropertyDataTypeLookup
40
	 */
41
	public static function getPropertyDataTypeLookup( MediaWikiServices $services = null ) {
42
		return self::getService( $services, self::PROPERTY_DATA_TYPE_LOOKUP );
43
	}
44
45
}
46