Completed
Push — master ( 82b9ae...b792a1 )
by J.D.
02:52
created

WordPoints_Hook_Firer::do_event()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 41
Code Lines 20

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 41
rs 6.7273
cc 7
eloc 20
nc 8
nop 2
1
<?php
2
3
/**
4
 * Hook firer class.
5
 *
6
 * @package wordpoints-hooks-api
7
 * @since   1.0.0
8
 */
9
10
/**
11
 * Fires a hook event.
12
 *
13
 * @since 1.0.0
14
 */
15
class WordPoints_Hook_Firer implements WordPoints_Hook_FirerI {
16
17
	/**
18
	 * @since 1.0.0
19
	 */
20
	public function do_event( $event_slug, WordPoints_Hook_Event_Args $event_args ) {
21
22
		$hooks = wordpoints_hooks();
23
24
		/** @var WordPoints_Hook_Reactor $reactor */
25
		foreach ( $hooks->reactors->get_all() as $reactor ) {
26
27
			foreach ( $reactor->get_all_reactions_to_event( $event_slug ) as $reaction ) {
28
29
				$validator = new WordPoints_Hook_Reaction_Validator(
30
					$reaction
31
					, $reactor
32
					, true
33
				);
34
35
				$validator->validate();
36
37
				if ( $validator->had_errors() ) {
38
					continue;
39
				}
40
41
				$event_args->set_validator( $validator );
42
				$reaction = $validator;
43
44
				/** @var WordPoints_Hook_Extension[] $extensions */
45
				$extensions = $hooks->extensions->get_all();
46
47
				foreach ( $extensions as $extension ) {
48
					if ( ! $extension->should_hit( $reaction, $event_args ) ) {
49
						continue 2;
50
					}
51
				}
52
53
				$reactor->hit( $event_args, $reaction );
54
55
				foreach ( $extensions as $extension ) {
56
					$extension->after_hit( $reaction, $event_args );
57
				}
58
			}
59
		}
60
	}
61
}
62
63
// EOF
64