HookRegistry   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 65
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isRegistered() 0 3 1
A getHandlerFor() 0 3 2
A clear() 0 5 2
A register() 0 5 2
A addCallbackHandlers() 0 7 1
1
<?php
2
3
namespace SMW\Scribunto;
4
5
use Hooks;
6
7
/**
8
 * @license GNU GPL v2+
9
 * @since 1.0
10
 *
11
 * @author mwjames
12
 */
13
class HookRegistry {
14
15
	/**
16
	 * @var array
17
	 */
18
	private $handlers = [];
19
20
	/**
21
	 * @since 1.0
22
	 *
23
	 * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
24
	 */
25 20
	public function __construct() {
26 20
		$this->addCallbackHandlers();
27 20
	}
28
29
	/**
30
	 * @since  1.0
31
	 */
32 18
	public function clear() {
33 18
		foreach ( $this->handlers as $name => $callback ) {
34 18
			Hooks::clear( $name );
35
		}
36 18
	}
37
38
	/**
39
	 * @since  1.0
40
	 */
41 19
	public function register() {
42 19
		foreach ( $this->handlers as $name => $callback ) {
43 19
			Hooks::register( $name, $callback );
44
		}
45 19
	}
46
47
	/**
48
	 * @since  1.0
49
	 *
50
	 * @param string $name
51
	 *
52
	 * @return boolean
53
	 */
54 1
	public function isRegistered( $name ) {
55 1
		return Hooks::isRegistered( $name );
56
	}
57
58
	/**
59
	 * @since  1.0
60
	 *
61
	 * @param string $name
62
	 *
63
	 * @return Callable|false
64
	 */
65 1
	public function getHandlerFor( $name ) {
66 1
		return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false;
67
	}
68
69
	private function addCallbackHandlers() {
70
71 19
		$this->handlers['ScribuntoExternalLibraries'] = function( $engine, array &$extraLibraries ) {
72 19
			$extraLibraries['mw.smw'] = 'SMW\Scribunto\ScribuntoLuaLibrary';
73 19
			return true;
74
		};
75 20
	}
76
77
}
78