Passed
Push — master ( ff4a98...d2efa5 )
by Warwick
04:51
created

Workout::settings()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 199
Code Lines 155

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 155
c 3
b 0
f 0
nc 4
nop 1
dl 0
loc 199
rs 8

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Contains the settings class for LSX
4
 *
5
 * @package lsx-health-plan
6
 */
7
8
namespace lsx_health_plan\classes\admin;
9
10
/**
11
 * Contains the settings for each post type \lsx_health_plan\classes\admin\Workout().
12
 */
13
class Workout {
14
15
	/**
16
	 * Holds class instance
17
	 *
18
	 * @since 1.0.0
19
	 *
20
	 * @var      object \lsx_health_plan\classes\admin\Workout()
21
	 */
22
	protected static $instance = null;
23
24
	/**
25
	 * Constructor
26
	 */
27
	public function __construct() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
28
		add_action( 'lsx_hp_settings_page_workout_top', array( $this, 'settings' ), 1, 1 );
29
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
30
31
	/**
32
	 * Return an instance of this class.
33
	 *
34
	 * @since 1.0.0
35
	 *
36
	 * @return    object \lsx_health_plan\classes\admin\Workout()    A single instance of this class.
37
	 */
38
	public static function get_instance() {
39
		// If the single instance hasn't been set, set it now.
40
		if ( null === self::$instance ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
41
			self::$instance = new self();
42
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
43
		return self::$instance;
44
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
45
46
	/**
47
	 * Registers the general settings.
48
	 *
49
	 * @param object $cmb new_cmb2_box().
50
	 * @return void
51
	 */
52
	public function settings( $cmb ) {
53
		$cmb->add_field(
54
			array(
55
				'name'        => __( 'Disable Workouts', 'lsx-health-plan' ),
56
				'id'          => 'workout_disabled',
57
				'type'        => 'checkbox',
58
				'value'       => 1,
59
				'default'     => 0,
60
				'description' => __( 'Disable workout post type if you are wanting a minimal site.', 'lsx-health-plan' ),
61
			)
62
		);
63
		$cmb->add_field(
64
			array(
65
				'name'    => __( 'Your Warm-up Intro', 'lsx-health-plan' ),
66
				'id'      => 'warmup_intro',
67
				'type'    => 'textarea_small',
68
				'value'   => '',
69
				'default' => __( "Don't forget your warm-up! It's a vital part of your daily workout routine.", 'lsx-health-plan' ),
70
			)
71
		);
72
		if ( post_type_exists( 'workout' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
73
			$cmb->add_field(
74
				array(
75
					'name'    => __( 'Your Workout Intro', 'lsx-health-plan' ),
76
					'id'      => 'workout_intro',
77
					'type'    => 'textarea_small',
78
					'value'   => '',
79
					'default' => __( "Let's do this! Smash your daily workout and reach your fitness goals.", 'lsx-health-plan' ),
80
				)
81
			);
82
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
83
		$cmb->add_field(
84
			array(
85
				'before_row'  => '<h4><b><u>Layout Options</u></b></h4>',
86
				'id'          => 'workout_tab_layout',
87
				'type'        => 'select',
88
				'name'        => __( 'Workout Tab Layout', 'lsx-health-plan' ),
89
				'description' => __( 'Choose the layout for the workouts.', 'lsx-health-plan' ),
90
				'options'     => array(
91
					'table' => __( 'Table', 'lsx-health-plan' ),
92
					'list'  => __( 'List', 'lsx-health-plan' ),
93
					'grid'  => __( 'Grid', 'lsx-health-plan' ),
94
				),
95
			)
96
		);
97
		$cmb->add_field(
98
			array(
99
				'id'          => 'workout_tab_link',
100
				'type'        => 'select',
101
				'name'        => __( 'Workout Tab Link', 'lsx-health-plan' ),
102
				'description' => __( 'Choose to show the excerpt, full content or nothing.', 'lsx-health-plan' ),
103
				'options'     => array(
104
					'none'   => __( 'None', 'lsx-health-plan' ),
105
					'single' => __( 'Single', 'lsx-health-plan' ),
106
					'modal'  => __( 'Modal', 'lsx-health-plan' ),
107
				),
108
				'default' => '',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 5 space(s) between "'default'" and double arrow, but found 1.
Loading history...
109
			)
110
		);
111
		$cmb->add_field(
112
			array(
113
				'id'          => 'workout_tab_modal_content',
114
				'type'        => 'select',
115
				'name'        => __( 'Modal Content', 'lsx-health-plan' ),
116
				'description' => __( 'Choose to show the excerpt, full content or nothing. For the modal content only', 'lsx-health-plan' ),
117
				'options'     => array(
118
					''        => __( 'None', 'lsx-health-plan' ),
119
					'excerpt' => __( 'Excerpt', 'lsx-health-plan' ),
120
					'full'    => __( 'Full Content', 'lsx-health-plan' ),
121
				),
122
				'default' => '',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 5 space(s) between "'default'" and double arrow, but found 1.
Loading history...
123
			)
124
		);
125
		$cmb->add_field(
126
			array(
127
				'id'          => 'workout_tab_columns',
128
				'type'        => 'select',
129
				'name'        => __( 'Grid Columns', 'lsx-health-plan' ),
130
				'description' => __( 'If you are displaying a grid, set the amount of columns you want to use.', 'lsx-health-plan' ),
131
				'options'     => array(
132
					'12' => __( '1', 'lsx-health-plan' ),
133
					'6'  => __( '2', 'lsx-health-plan' ),
134
					'4'  => __( '3', 'lsx-health-plan' ),
135
					'3'  => __( '4', 'lsx-health-plan' ),
136
					'2'  => __( '6', 'lsx-health-plan' ),
137
				),
138
				'default' => '4',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 5 space(s) between "'default'" and double arrow, but found 1.
Loading history...
139
			)
140
		);
141
		$cmb->add_field(
142
			array(
143
				'id'          => 'workout_tab_content',
144
				'type'        => 'select',
145
				'name'        => __( 'Grid Content', 'lsx-health-plan' ),
146
				'description' => __( 'Choose to show the excerpt, full content or nothing. For the grid layout only', 'lsx-health-plan' ),
147
				'options'     => array(
148
					''        => __( 'None', 'lsx-health-plan' ),
149
					'excerpt' => __( 'Excerpt', 'lsx-health-plan' ),
150
					'full'    => __( 'Full Content', 'lsx-health-plan' ),
151
				),
152
				'default'     => '',
153
			)
154
		);
155
156
		$cmb->add_field(
157
			array(
158
				'before_row' => '<h4><b><u>URL Slug Options</u></b></h4><p style="font-style: italic;">If you need to translate the custom slug for this custom post type, do so below.</p>',
159
				'name'       =>  __( 'Single Workout Slug', 'lsx-health-plan' ),
0 ignored issues
show
introduced by
Expected 1 space after "=>"; 2 found
Loading history...
160
				'id'         => 'endpoint_workout',
161
				'type'       => 'input',
162
				'value'      => '',
163
				'default'    => 'workout',
164
			)
165
		);
166
		$cmb->add_field(
167
			array(
168
				'name'    =>  __( 'Workouts Archive Slug', 'lsx-health-plan' ),
0 ignored issues
show
introduced by
Expected 1 space after "=>"; 2 found
Loading history...
169
				'id'      => 'endpoint_workout_archive',
170
				'type'    => 'input',
171
				'value'   => '',
172
				'default' => 'workouts',
173
			)
174
		);
175
		$cmb->add_field(
176
			array(
177
				'name'    =>  __( 'Warm Up Slug', 'lsx-health-plan' ),
0 ignored issues
show
introduced by
Expected 1 space after "=>"; 2 found
Loading history...
178
				'id'      => 'endpoint_warm_up',
179
				'type'    => 'input',
180
				'value'   => '',
181
				'default' => 'warm-up',
182
			)
183
		);
184
		
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
185
		
186
		$cmb->add_field(
187
			array(
188
				'before_row'  => '<h4><b><u>Default Options</u></b></h4>',
189
				'name'        => __( 'Warm Up', 'lsx-health-plan' ),
190
				'description' => __( 'Set a default warm up routine.', 'lsx-health-plan' ),
191
				'limit'       => 1,
192
				'id'          => 'plan_warmup',
193
				'type'        => 'post_search_ajax',
194
				'query_args'  => array(
195
					'post_type'      => 'post',
196
					'post_status'    => array( 'publish' ),
197
					'posts_per_page' => -1,
198
				),
199
			)
200
		);
201
		$cmb->add_field(
202
			array(
203
				'name'        => __( 'Workout', 'lsx-health-plan' ),
204
				'description' => __( 'Set a default workout routine.', 'lsx-health-plan' ),
205
				'limit'       => 1,
206
				'id'          => 'connected_workouts',
207
				'type'        => 'post_search_ajax',
208
				'query_args'  => array(
209
					'post_type'      => 'workout',
210
					'post_status'    => array( 'publish' ),
211
					'posts_per_page' => -1,
212
				),
213
			)
214
		);
215
		if ( function_exists( 'download_monitor' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
216
			$page_url    = 'https://wordpress.org/plugins/download-monitor/';
217
			$plugin_name = 'Download Monitor';
218
			$description = sprintf(
219
				/* translators: %s: The subscription info */
220
				__( 'If you are using <a target="_blank" href="%1$s">%2$s</a> you can set a default download file for your meal here.', 'lsx-search' ),
221
				$page_url,
222
				$plugin_name
223
			);
224
			$cmb->add_field(
225
				array(
226
					'name'        => __( 'Default Warm Up PDF', 'lsx-health-plan' ),
227
					'description' => $description,
228
					'id'          => 'download_page',
229
					'type'        => 'post_search_ajax',
230
					'limit'       => 1,
231
					'query_args'  => array(
232
						'post_type'      => array( 'dlm_download' ),
233
						'post_status'    => array( 'publish' ),
234
						'posts_per_page' => -1,
235
					),
236
				)
237
			);
238
			$cmb->add_field(
239
				array(
240
					'name'        => __( 'Default Workout PDF', 'lsx-health-plan' ),
241
					'description' => $description,
242
					'id'          => 'download_workout',
243
					'type'        => 'post_search_ajax',
244
					'limit'       => 1,
245
					'query_args'  => array(
246
						'post_type'      => array( 'dlm_download' ),
247
						'post_status'    => array( 'publish' ),
248
						'posts_per_page' => -1,
249
					),
250
					'after_row'   => __( '<p style="font-style: italic;">If you have changed any URL slugs, please remember re-save your permalinks in Settings > Permalinks.</p>', 'lsx-health-plan' ),
251
				)
252
			);
253
		}
254
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
255
}
256
Workout::get_instance();
257