Requests_Hooks   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A register() 0 10 3
A dispatch() 0 13 4
1
<?php
2
/**
3
 * Handles adding and dispatching events
4
 *
5
 * @package Requests
6
 * @subpackage Utilities
7
 */
8
9
/**
10
 * Handles adding and dispatching events
11
 *
12
 * @package Requests
13
 * @subpackage Utilities
14
 */
15
class Requests_Hooks implements Requests_Hooker {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
16
	/**
17
	 * Registered callbacks for each hook
18
	 *
19
	 * @var array
20
	 */
21
	protected $hooks = array();
22
23
	/**
24
	 * Constructor
25
	 */
26
	public function __construct() {
27
		// pass
28
	}
29
30
	/**
31
	 * Register a callback for a hook
32
	 *
33
	 * @param string $hook Hook name
34
	 * @param callback $callback Function/method to call on event
35
	 * @param int $priority Priority number. <0 is executed earlier, >0 is executed later
36
	 */
37
	public function register($hook, $callback, $priority = 0) {
38
		if (!isset($this->hooks[$hook])) {
39
			$this->hooks[$hook] = array();
40
		}
41
		if (!isset($this->hooks[$hook][$priority])) {
42
			$this->hooks[$hook][$priority] = array();
43
		}
44
45
		$this->hooks[$hook][$priority][] = $callback;
46
	}
47
48
	/**
49
	 * Dispatch a message
50
	 *
51
	 * @param string $hook Hook name
52
	 * @param array $parameters Parameters to pass to callbacks
53
	 * @return boolean Successfulness
54
	 */
55
	public function dispatch($hook, $parameters = array()) {
56
		if (empty($this->hooks[$hook])) {
57
			return false;
58
		}
59
60
		foreach ($this->hooks[$hook] as $priority => $hooked) {
61
			foreach ($hooked as $callback) {
62
				call_user_func_array($callback, $parameters);
63
			}
64
		}
65
66
		return true;
67
	}
68
}