Completed
Push — master ( f41943...71e1d7 )
by
unknown
01:52
created

WikibaseServices   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getService() 0 6 2
A getEntityLookup() 0 3 1
A getPropertyDataTypeLookup() 0 3 1
A getEntityLookupWithoutCache() 0 3 1
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
	const ENTITY_LOOKUP_WIHTOUT_CACHE = 'WBQC_EntityLookupWithoutCache';
22
23
	private static function getService( MediaWikiServices $services = null, $name ) {
24
		if ( $services === null ) {
25
			$services = MediaWikiServices::getInstance();
26
		}
27
		return $services->getService( $name );
28
	}
29
30
	/**
31
	 * @param MediaWikiServices|null $services
32
	 * @return EntityLookup
33
	 */
34
	public static function getEntityLookup( MediaWikiServices $services = null ) {
35
		return self::getService( $services, self::ENTITY_LOOKUP );
36
	}
37
38
	/**
39
	 * @param MediaWikiServices|null $services
40
	 * @return PropertyDataTypeLookup
41
	 */
42
	public static function getPropertyDataTypeLookup( MediaWikiServices $services = null ) {
43
		return self::getService( $services, self::PROPERTY_DATA_TYPE_LOOKUP );
44
	}
45
46
	/**
47
	 * @param MediaWikiServices|null $services
48
	 * @return EntityLookup
49
	 */
50
	public static function getEntityLookupWithoutCache( MediaWikiServices $services = null ) {
51
		return self::getService( $services, self::ENTITY_LOOKUP_WIHTOUT_CACHE );
52
	}
53
54
}
55