Completed
Branch BUG-10381-asset-loading (f91422)
by
unknown
170:16 queued 157:41
created

EED_Ticket_Selector   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 340
Duplicated Lines 4.12 %

Coupling/Cohesion

Components 3
Dependencies 10

Importance

Changes 0
Metric Value
dl 14
loc 340
rs 9.8
c 0
b 0
f 0
wmc 31
lcom 3
cbo 10

23 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 3 1
A set_config() 0 5 1
A set_hooks() 0 8 1
A set_hooks_admin() 0 9 1
A set_definitions() 0 10 2
A ticketSelector() 0 7 2
A run() 0 1 1
A getIframeEmbedButton() 0 6 2
A ticket_selector_iframe_embed_button() 0 4 1
A ticket_selector_iframe() 0 4 1
A display_ticket_selector() 0 3 1
A process_ticket_selections() 0 4 1
A cancel_ticket_selections() 0 5 1
A load_tckt_slctr_assets() 0 10 2
A display_view_details_btn() 0 5 1
A display_ticket_selector_submit() 0 5 1
A iframe_code_button() 7 12 3
A ticket_selector_form_open() 0 5 1
A ticket_selector_form_close() 0 5 1
A no_tkt_slctr_end_dv() 0 5 1
A tkt_slctr_end_dv() 0 4 1
A clear_tkt_slctr() 0 4 1
A load_tckt_slctr_assets_admin() 7 11 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php use EventEspresso\modules\ticket_selector\DisplayTicketSelector;
2
use EventEspresso\modules\ticket_selector\ProcessTicketSelector;
3
use EventEspresso\modules\ticket_selector\TicketSelectorIframe;
4
use EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton;
5
6
if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
7
	exit( 'No direct script access allowed' );
8
}
9
10
11
12
/**
13
 * ------------------------------------------------------------------------
14
 *
15
 * Ticket Selector  class
16
 *
17
 * @package		Event Espresso
18
 * @subpackage	includes/classes/EE_Ticket_Selector.class.php
19
 * @author		Brent Christensen
20
 *
21
 * ------------------------------------------------------------------------
22
 */
23
class EED_Ticket_Selector extends  EED_Module {
24
25
    /**
26
     * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector
27
     */
28
    private static $ticket_selector;
29
30
    /**
31
     * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button
32
     */
33
    private static $iframe_embed_button;
34
35
36
37
	/**
38
	 * @return EED_Ticket_Selector
39
	 */
40
	public static function instance() {
41
		return parent::get_instance( __CLASS__ );
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (get_instance() instead of instance()). Are you sure this is correct? If so, you might want to change this to $this->get_instance().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
42
	}
43
44
45
46
	protected function set_config(){
47
		$this->set_config_section( 'template_settings' );
48
		$this->set_config_class( 'EE_Ticket_Selector_Config' );
49
		$this->set_config_name( 'EED_Ticket_Selector' );
50
	}
51
52
53
54
	/**
55
	 * 	set_hooks - for hooking into EE Core, other modules, etc
56
	 *
57
	 *  @access 	public
58
	 *  @return 	void
59
	 */
60
	public static function set_hooks() {
61
		// routing
62
		EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' );
63
		EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' );
64
		add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 );
65
		add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 );
66
		add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 );
67
	}
68
69
70
71
	/**
72
	 * 	set_hooks_admin - for hooking into EE Admin Core, other modules, etc
73
	 *
74
	 *  @access 	public
75
	 *  @return 	void
76
	 */
77
	public static function set_hooks_admin() {
78
		// hook into the end of the \EE_Admin_Page::_load_page_dependencies()
79
		// to load assets for "espresso_events" page on the "edit" route (action)
80
		add_action(
81
			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit',
82
			array( 'EED_Ticket_Selector', 'ticket_selector_iframe_embed_button' ),
83
			10
84
		);
85
    }
86
87
88
89
	/**
90
	 * 	set_definitions
91
	 *
92
	 *  @access 	public
93
	 *  @return 	void
94
	 */
95
	public static function set_definitions() {
96
		define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
97
		define( 'TICKET_SELECTOR_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS );
98
99
		//if config is not set, initialize
100
		//If config is not set, set it.
101
		if ( ! isset( EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector ) ) {
102
			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = new EE_Ticket_Selector_Config();
103
		}
104
	}
105
106
107
108
	/**
109
     * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector
110
     */
111
    public static function ticketSelector()
112
    {
113
        if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
114
            EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector();
115
        }
116
        return EED_Ticket_Selector::$ticket_selector;
117
    }
118
119
120
	/**
121
	 * 	gets the ball rolling
122
	 *
123
	 *	@access public
124
	 * 	@param	WP $WP
125
	 * 	@return void
126
	 */
127
	public function run( $WP ) {}
128
129
130
131
	/**
132
	 * @return \EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton
133
	 */
134
	public static function getIframeEmbedButton() {
135
		if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton ) {
136
			self::$iframe_embed_button = new TicketSelectorIframeEmbedButton();
137
		}
138
		return self::$iframe_embed_button;
139
	}
140
141
142
143
	/**
144
	 * ticket_selector_iframe_embed_button
145
	 *
146
	 * @return    void
147
	 * @throws \EE_Error
148
	 */
149
	public static function ticket_selector_iframe_embed_button() {
150
		$iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
151
		$iframe_embed_button->addEventEditorIframeEmbedButton();
152
	}
153
154
155
156
    /**
157
     * ticket_selector_iframe
158
     *
159
     * @return    void
160
     * @throws \DomainException
161
     * @throws \EE_Error
162
     */
163
	public function ticket_selector_iframe() {
164
		$ticket_selector_iframe = new TicketSelectorIframe();
165
		$ticket_selector_iframe->display();
166
	}
167
168
169
170
    /**
171
     *    creates buttons for selecting number of attendees for an event
172
     *
173
     * @access    public
174
     * @param    WP_Post|int $event
175
     * @param    bool        $view_details
176
     * @return    string
177
     * @throws \EE_Error
178
     */
179
	public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) {
180
		return EED_Ticket_Selector::ticketSelector()->display( $event, $view_details );
181
	}
182
183
184
185
	/**
186
	 * process_ticket_selections
187
	 *
188
	 * @access        public
189
	 * @access        public
190
	 * @return        array  or FALSE
191
	 * @throws \EE_Error
192
	 */
193
	public function process_ticket_selections() {
194
		$form = new ProcessTicketSelector();
195
		return $form->processTicketSelections();
196
	}
197
198
199
200
    /**
201
     * cancel_ticket_selections
202
     *
203
     * @access        public
204
     * @return        string
205
     */
206
    public static function cancel_ticket_selections()
207
    {
208
        $form = new ProcessTicketSelector();
209
        return $form->cancelTicketSelections();
210
    }
211
212
213
214
	/**
215
	* 	load js
216
	*
217
	* 	@access 		public
218
	* 	@return 		void
219
	*/
220
	public static function load_tckt_slctr_assets() {
221
		if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) {
222
			// add some style
223
			wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css');
224
			wp_enqueue_style('ticket_selector');
225
			// make it dance
226
			// wp_register_script('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', array('espresso_core'), '', TRUE);
227
			// wp_enqueue_script('ticket_selector');
228
		}
229
	}
230
231
232
233
	/****************************** DEPRECATED ******************************/
234
235
236
237
    /**
238
     * @deprecated
239
     * @return string
240
     * @throws \EE_Error
241
     */
242
    public static function display_view_details_btn()
243
    {
244
        // todo add doing_it_wrong() notice during next major version
245
        return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton();
246
    }
247
248
249
250
    /**
251
     * @deprecated
252
     * @return string
253
     * @throws \EE_Error
254
     */
255
    public static function display_ticket_selector_submit()
256
    {
257
        // todo add doing_it_wrong() notice during next major version
258
        return EED_Ticket_Selector::ticketSelector()->displaySubmitButton();
259
    }
260
261
262
263
    /**
264
     * @deprecated
265
     * @param string $permalink_string
266
     * @param int    $id
267
     * @param string $new_title
268
     * @param string $new_slug
269
     * @return string
270
     */
271
    public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '')
0 ignored issues
show
Unused Code introduced by
The parameter $permalink_string is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $new_title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $new_slug is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
272
    {
273
        // todo add doing_it_wrong() notice during next major version
274 View Code Duplication
        if (
275
        	\EE_Registry::instance()->REQ->get('page') === 'espresso_events'
276
        	&& \EE_Registry::instance()->REQ->get('action') === 'edit'
277
        ) {
278
            $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
279
            $iframe_embed_button->addEventEditorIframeEmbedButton();
280
        }
281
        return '';
282
    }
283
284
285
286
    /**
287
     * @deprecated
288
     * @param int    $ID
289
     * @param string $external_url
290
     * @return string
291
     */
292
    public static function ticket_selector_form_open($ID = 0, $external_url = '')
293
    {
294
        // todo add doing_it_wrong() notice during next major version
295
        return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url);
296
    }
297
298
299
300
    /**
301
     * @deprecated
302
     * @return string
303
     */
304
    public static function ticket_selector_form_close()
305
    {
306
        // todo add doing_it_wrong() notice during next major version
307
        return EED_Ticket_Selector::ticketSelector()->formClose();
308
    }
309
310
311
312
    /**
313
     * @deprecated
314
     * @return string
315
     */
316
    public static function no_tkt_slctr_end_dv()
317
    {
318
        // todo add doing_it_wrong() notice during next major version
319
        return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv();
320
    }
321
322
323
324
    /**
325
     * @deprecated 4.9.13
326
     * @return string
327
     */
328
    public static function tkt_slctr_end_dv()
329
    {
330
        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
331
    }
332
333
334
335
    /**
336
     * @deprecated
337
     * @return string
338
     */
339
    public static function clear_tkt_slctr()
340
    {
341
        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
342
    }
343
344
345
346
    /**
347
     * @deprecated
348
     */
349
    public static function load_tckt_slctr_assets_admin()
350
    {
351
        // todo add doing_it_wrong() notice during next major version
352 View Code Duplication
	    if (
353
		    \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events'
354
		    && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit'
355
	    ) {
356
		    $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
357
            $iframe_embed_button->embedButtonAssets();
358
        }
359
    }
360
361
362
}
363
// End of file EED_Ticket_Selector.module.php
364
// Location: modules/ticket_selector/EED_Ticket_Selector.module.php
365