Passed
Push — add/multiplan ( efd4dd...2fc26f )
by Warwick
05:21 queued 14s
created

lsx_health_plan_has_workout()   B

Complexity

Conditions 7
Paths 9

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 13
nc 9
nop 1
dl 0
loc 20
rs 8.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * LSX Health Plan Conditional Helpers.
4
 *
5
 * @package lsx-health-plan
6
 */
7
8
/**
9
 * Checks if the current post or supplied $post_ID has a workout attached.
10
 *
11
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
12
 * @return boolean
13
 */
14
function lsx_health_plan_has_warmup( $post_id = '' ) {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
15
	if ( '' === $post_id ) {
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...
16
		$post_id = get_the_ID();
17
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
18
	return \lsx_health_plan\functions\has_attached_post( $post_id, 'plan_warmup' );
0 ignored issues
show
Bug introduced by
It seems like $post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

18
	return \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'plan_warmup' );
Loading history...
19
}
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...
20
21
/**
22
 * Checks if the current post or supplied $post_ID has a workout attached.
23
 *
24
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
25
 * @return boolean
26
 */
27
function lsx_health_plan_has_workout( $post_id = '' ) {
28
	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...
29
		return false;
30
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
31
	if ( '' === $post_id ) {
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...
32
		$post_id = get_the_ID();
33
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
34
	$has_workouts = false;
35
36
	$section_key = get_query_var( 'section', false );
37
	if ( false !== $section_key ) {
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...
38
		$section_info = \lsx_health_plan\functions\plan\get_section_info( $section_key );
39
		if ( isset( $section_info['connected_workouts'] ) && ! empty( $section_info['connected_workouts'] ) ) {
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...
40
			$has_workouts = true;
41
		}
42
	} elseif ( \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_workouts' ) ) {
0 ignored issues
show
Bug introduced by
It seems like $post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
	} elseif ( \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'connected_workouts' ) ) {
Loading history...
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...
43
		$has_workouts = true;
44
	}
45
46
	return $has_workouts;
47
}
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...
48
49
/**
50
 * Checks if the current post or supplied $post_ID has a meal attached.
51
 *
52
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
53
 * @return boolean
54
 */
55
function lsx_health_plan_has_meal( $post_id = '' ) {
56
	if ( ! post_type_exists( 'meal' ) ) {
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...
57
		return false;
58
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
59
	if ( '' === $post_id ) {
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...
60
		$post_id = get_the_ID();
61
	}
62
63
	return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_meals' );
0 ignored issues
show
Bug introduced by
It seems like $post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

63
	return \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'connected_meals' );
Loading history...
64
}
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...
65
66
/**
67
 * Checks if the current post or supplied $post_ID has a recipes attached.
68
 *
69
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
70
 * @return boolean
71
 */
72
function lsx_health_plan_has_recipe( $post_id = '' ) {
73
	if ( ! post_type_exists( 'recipe' ) ) {
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...
74
		return false;
75
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
76
	if ( '' === $post_id ) {
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...
77
		$post_id = get_the_ID();
78
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
79
	return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_recipes' );
0 ignored issues
show
Bug introduced by
It seems like $post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

79
	return \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'connected_recipes' );
Loading history...
80
}
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...
81
82
/**
83
 * Checks if the current post or supplied $post_ID has a downloads attached.
84
 *
85
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
86
 * @return boolean
87
 */
88
function lsx_health_plan_has_downloads( $post_id = '' ) {
89
	$has_downloads = false;
90
	if ( '' === $post_id ) {
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...
91
		$post_id = get_the_ID();
92
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
93
	$downloads = \lsx_health_plan\functions\get_downloads( 'all', $post_id );
94
	if ( ! empty( $downloads ) ) {
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...
95
		$has_downloads = true;
96
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
97
	return $has_downloads;
98
}
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...
99
100
/**
101
 * Checks if the current post or supplied $post_ID has a tips attached.
102
 *
103
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
104
 * @return boolean
105
 */
106
function lsx_health_plan_has_tip( $post_id = '' ) {
107
	if ( ! post_type_exists( 'tip' ) ) {
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...
108
		return false;
109
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
110
	if ( '' === $post_id ) {
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...
111
		$post_id = get_the_ID();
112
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
113
	return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_tips' );
0 ignored issues
show
Bug introduced by
It seems like $post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

113
	return \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'connected_tips' );
Loading history...
114
}
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...
115
116
/**
117
 * Checks if the current post or supplied $post_ID has a video attached.
118
 *
119
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
120
 * @return boolean
121
 */
122
function lsx_health_plan_has_video( $post_id = '' ) {
123
	if ( ! post_type_exists( 'video' ) ) {
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...
124
		return false;
125
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
126
	if ( '' === $post_id ) {
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...
127
		$post_id = get_the_ID();
128
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
129
	return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_videos' );
0 ignored issues
show
Bug introduced by
It seems like $post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

129
	return \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'connected_videos' );
Loading history...
130
}
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...
131
132
/**
133
 * Checks to see if the current user has a valid purchase.
134
 *
135
 * @return boolean
136
 */
137
function lsx_health_plan_user_has_purchase() {
138
	$valid_order = false;
139
	$product_id  = \lsx_health_plan\functions\get_option( 'membership_product', false );
140
141
	if ( is_user_logged_in() && false !== $product_id ) {
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...
142
		$current_user = wp_get_current_user();
143
		if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id ) ) {
0 ignored issues
show
Bug introduced by
The function wc_customer_bought_product was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

143
		if ( /** @scrutinizer ignore-call */ wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id ) ) {
Loading history...
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...
144
			$valid_order = true;
145
		}
146
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
147
	return $valid_order;
148
}
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...
149
150
/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$needle" missing
Loading history...
151
 * Checks if the current post or supplied $post_ID has a tips attached.
152
 *
153
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $post_id does not match actual variable name $needle
Loading history...
154
 * @return boolean
155
 */
156
function lsx_health_plan_is_current_tab( $needle = '' ) {
157
	$is_tab = false;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
158
	$plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false );
159
	if ( false === $plan_slug ) {
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...
160
		$plan_slug = 'my-plan';
161
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
162
	if ( is_singular( 'plan' ) || is_page( $plan_slug ) ) {
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...
163
		$endpoint = get_query_var( 'endpoint' );
164
		if ( false !== $endpoint && $needle === $endpoint ) {
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...
165
			$is_tab = true;
166
		}
167
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
168
	return $is_tab;
169
}
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...
170
171
/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$section_key" missing
Loading history...
172
 * Checks to see if the current day is complete or not
173
 *
174
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
175
 * @return boolean
176
 */
177
function lsx_health_plan_is_day_complete( $post_id = '', $section_key = '' ) {
178
	$is_complete = false;
179
	if ( '' === $post_id ) {
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...
180
		$post_id = get_the_ID();
181
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
182
	$key             = \lsx_health_plan\functions\plan\generate_section_id( $section_key );
183
	$is_day_complete = get_user_meta( get_current_user_id(), 'day_' . $key . '_complete', true );
184
	if ( false !== $is_day_complete && '' !== $is_day_complete ) {
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...
185
		$is_complete = true;
186
	}
187
188
	return $is_complete;
189
}
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...
190
191
function lsx_health_plan_is_plan_complete() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_health_plan_is_plan_complete()
Loading history...
192
	$complete = false;
193
	return $complete;
194
}
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...
195
196
/**
197
 * Checks if the current week has any downloads attached.
198
 *
199
 * @param string $week The week name 'week-1'.
200
 * @return boolean
201
 */
202
function lsx_health_plan_week_has_downloads( $week = '' ) {
203
	$has_downloads = false;
204
	if ( '' !== $week ) {
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...
205
		$downloads = \lsx_health_plan\functions\get_weekly_downloads( $week );
206
		if ( ! empty( $downloads ) ) {
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...
207
			$has_downloads = true;
208
		}
209
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
210
	return $has_downloads;
211
}
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...
212
213
/**
214
 * Checks to see if the current ID has any tips attached.
215
 *
216
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
217
 * @return boolean
218
 */
219
function lsx_health_plan_has_tips( $post_id = '' ) {
220
	$has_tips = false;
221
	if ( '' === $post_id ) {
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...
222
		$post_id = get_the_ID();
223
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
224
	$post_type      = get_post_type( $post_id );
0 ignored issues
show
Bug introduced by
It seems like $post_id can also be of type false and string; however, parameter $post of get_post_type() does only seem to accept WP_Post|integer|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

224
	$post_type      = get_post_type( /** @scrutinizer ignore-type */ $post_id );
Loading history...
225
	$connected_tips = get_post_meta( get_the_ID(), $post_type . '_connected_tips', true );
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $post_id of get_post_meta() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

225
	$connected_tips = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), $post_type . '_connected_tips', true );
Loading history...
226
	$connected_tips = \lsx_health_plan\functions\check_posts_exist( $connected_tips );
0 ignored issues
show
Bug introduced by
It seems like $connected_tips can also be of type false and string; however, parameter $post_ids of lsx_health_plan\functions\check_posts_exist() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

226
	$connected_tips = \lsx_health_plan\functions\check_posts_exist( /** @scrutinizer ignore-type */ $connected_tips );
Loading history...
227
	if ( ! empty( $connected_tips ) ) {
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...
228
		$has_tips = true;
229
	}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
230
	return $has_tips;
231
}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
232