Completed
Push — master ( 6d1705...9d80f0 )
by Jeroen De
02:45
created

IdGeneratorSetup   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 30
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A onExtensionFunction() 0 21 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace IdGenerator;
6
7
use MediaWiki\MediaWikiServices;
8
use Parser;
9
10
class IdGeneratorSetup {
11
12
	/**
13
	 * @var IdGeneratorFactory
14
	 */
15
	private static $factory;
16
17 1
	public static function onExtensionFunction() {
18
		self::$factory = new IdGeneratorFactory();
19
20 1
		$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) {
21 1
			foreach ( [ 'generate_id', 'generateid' ] as $functionName ) {
22 1
				$parser->setFunctionHook(
23 1
					$functionName,
24 1
					function ( Parser $parser, string $param = '' ) {
25 1
						$generator = self::$factory->getIdGenerator(
26 1
							MediaWikiServices::getInstance()->getDBLoadBalancer()
27
						);
28
29
						return [
30 1
							$generator->getNewId( $param ),
31
							'noparse' => true
32
						];
33 1
					}
34
				);
35
			}
36 1
		};
37
	}
38
39
}
40