Completed
Pull Request — master (#858)
by
unknown
40:08 queued 20:01
created

Yikes_Inc_Easy_Mailchimp_Extender_Loader::run()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8

Duplication

Lines 6
Ratio 75 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 6
loc 8
ccs 0
cts 8
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Register all actions and filters for the plugin
4
 *
5
 * @link       https://www.yikesplugins.com/
6
 * @since      6.0.0
7
 *
8
 * @package    Yikes_Inc_Easy_Mailchimp_Extender
9
 * @subpackage Yikes_Inc_Easy_Mailchimp_Extender/includes
10
 */
11
/**
12
 * Register all actions and filters for the plugin.
13
 *
14
 * Maintain a list of all hooks that are registered throughout
15
 * the plugin, and register them with the WordPress API. Call the
16
 * run function to execute the list of actions and filters.
17
 *
18
 * @package    Yikes_Inc_Easy_Mailchimp_Extender
19
 * @subpackage Yikes_Inc_Easy_Mailchimp_Extender/includes
20
 * @author     YIKES Inc. <[email protected]>
21
 */
22
class Yikes_Inc_Easy_Mailchimp_Extender_Loader {
23
	/**
24
	 * The array of actions registered with WordPress.
25
	 *
26
	 * @since    6.0.0
27
	 * @access   protected
28
	 * @var      array    $actions    The actions registered with WordPress to fire when the plugin loads.
29
	 */
30
	protected $actions;
31
	/**
32
	 * The array of filters registered with WordPress.
33
	 *
34
	 * @since    6.0.0
35
	 * @access   protected
36
	 * @var      array    $filters    The filters registered with WordPress to fire when the plugin loads.
37
	 */
38
	protected $filters;
39
	/**
40
	 * Initialize the collections used to maintain the actions and filters.
41
	 *
42
	 * @since    6.0.0
43
	 */
44
	public function __construct() {
45
		$this->actions = array();
46
		$this->filters = array();
47
	}
48
	/**
49
	 * Add a new action to the collection to be registered with WordPress.
50
	 *
51
	 * @since    6.0.0
52
	 * @param      string               $hook             The name of the WordPress action that is being registered.
53
	 * @param      object               $component        A reference to the instance of the object on which the action is defined.
54
	 * @param      string               $callback         The name of the function definition on the $component.
55
	 * @param      int      Optional    $priority         The priority at which the function should be fired.
56
	 * @param      int      Optional    $accepted_args    The number of arguments that should be passed to the $callback.
57
	 */
58
	public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
59
		$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
60
	}
61
	/**
62
	 * Add a new filter to the collection to be registered with WordPress.
63
	 *
64
	 * @since    6.0.0
65
	 * @param      string               $hook             The name of the WordPress filter that is being registered.
66
	 * @param      object               $component        A reference to the instance of the object on which the filter is defined.
67
	 * @param      string               $callback         The name of the function definition on the $component.
68
	 * @param      int      Optional    $priority         The priority at which the function should be fired.
69
	 * @param      int      Optional    $accepted_args    The number of arguments that should be passed to the $callback.
70
	 */
71
	public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
72
		$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
73
	}
74
	/**
75
	 * A utility function that is used to register the actions and hooks into a single
76
	 * collection.
77
	 *
78
	 * @since    6.0.0
79
	 * @access   private
80
	 * @param      array                $hooks            The collection of hooks that is being registered (that is, actions or filters).
81
	 * @param      string               $hook             The name of the WordPress filter that is being registered.
82
	 * @param      object               $component        A reference to the instance of the object on which the filter is defined.
83
	 * @param      string               $callback         The name of the function definition on the $component.
84
	 * @param      int      Optional    $priority         The priority at which the function should be fired.
85
	 * @param      int      Optional    $accepted_args    The number of arguments that should be passed to the $callback.
86
	 * @return   type                                   The collection of actions and filters registered with WordPress.
87
	 */
88
	private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
89
		$hooks[] = array(
90
			'hook'          => $hook,
91
			'component'     => $component,
92
			'callback'      => $callback,
93
			'priority'      => $priority,
94
			'accepted_args' => $accepted_args
95
		);
96
		return $hooks;
97
	}
98
	/**
99
	 * Register the filters and actions with WordPress.
100
	 *
101
	 * @since    6.0.0
102
	 */
103
	public function run() {
104 View Code Duplication
		foreach ( $this->filters as $hook ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
			add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
106
		}
107 View Code Duplication
		foreach ( $this->actions as $hook ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
			add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
109
		}
110
	}
111
}