Completed
Push — master ( 852bc6...6d1705 )
by Jeroen De
02:21
created

IdGeneratorSetup   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 22
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A onExtensionFunction() 0 18 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
	public static function onExtensionFunction() {
13 1
		$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) {
14 1
			foreach ( [ 'generate_id', 'generateid' ] as $functionName ) {
15 1
				$parser->setFunctionHook(
16 1
					$functionName,
17 1
					function ( Parser $parser, string $param = '' ) {
18 1
						$generator = ( new IdGeneratorFactory() )->newIdGenerator(
19 1
							MediaWikiServices::getInstance()->getDBLoadBalancer()
20
						);
21
22
						return [
23 1
							$generator->getNewId( $param )
24
						];
25 1
					}
26
				);
27
			}
28 1
		};
29
	}
30
31
}
32