HookRegistry   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 59
rs 10
c 0
b 0
f 0
ccs 18
cts 18
cp 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A register() 0 5 2
A isRegistered() 0 3 1
A getHandlerFor() 0 3 2
A addCallbackHandlers() 0 10 1
1
<?php
2
3
namespace SEQL;
4
5
use Hooks;
6
use SMW\Store;
7
8
/**
9
 * @license GNU GPL v2+
10
 * @since 1.0
11
 *
12
 * @author mwjames
13
 */
14
class HookRegistry {
15
16
	/**
17
	 * @var array
18
	 */
19
	private $handlers = array();
20
21
	/**
22
	 * @since 1.0
23
	 *
24
	 * @param array $options
25
	 */
26 10
	public function __construct( array $options ) {
27 10
		$this->addCallbackHandlers( $options );
28 10
	}
29
30
	/**
31
	 * @since  1.0
32
	 */
33 9
	public function register() {
34 9
		foreach ( $this->handlers as $name => $callback ) {
35 9
			Hooks::register( $name, $callback );
36 9
		}
37 9
	}
38
39
	/**
40
	 * @since  1.0
41
	 *
42
	 * @param string $name
43
	 *
44
	 * @return boolean
45
	 */
46 1
	public function isRegistered( $name ) {
47 1
		return Hooks::isRegistered( $name );
48
	}
49
50
	/**
51
	 * @since  1.0
52
	 *
53
	 * @param string $name
54
	 *
55
	 * @return Callable|false
56
	 */
57 1
	public function getHandlerFor( $name ) {
58 1
		return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false;
59
	}
60
61 10
	private function addCallbackHandlers( $options ) {
62
63 10
		$dynamicInterwikiPrefixLoader = new DynamicInterwikiPrefixLoader(
64 10
			$options['externalRepositoryEndpoints']
65 10
		);
66
67
		$this->handlers['InterwikiLoadPrefix'] = function( $prefix, &$interwiki ) use( $dynamicInterwikiPrefixLoader ) {
68 2
			return $dynamicInterwikiPrefixLoader->tryToLoadIwMapForExternalRepository( $prefix, $interwiki );
69
		};
70 10
	}
71
72
}
73