Passed
Push — add/multiplan ( 42d7d0...ed804d )
by Warwick
04:03 queued 10s
created

lsx_health_plan_is_plan_complete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
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
12
 * @return boolean
13
 */
14
function lsx_health_plan_has_warmup( $post_id = '' ) {
15
	if ( '' === $post_id ) {
16
		$post_id = get_the_ID();
17
	}
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
}
20
21
/**
22
 * Checks if the current post or supplied $post_ID has a workout attached.
23
 *
24
 * @param string $post_id
25
 * @return boolean
26
 */
27
function lsx_health_plan_has_workout( $post_id = '' ) {
28
	if ( ! post_type_exists( 'workout' ) ) {
29
		return false;
30
	}
31
	if ( '' === $post_id ) {
32
		$post_id = get_the_ID();
33
	}
34
	return \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

34
	return \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'connected_workouts' );
Loading history...
35
}
36
37
/**
38
 * Checks if the current post or supplied $post_ID has a meal attached.
39
 *
40
 * @param string $post_id
41
 * @return boolean
42
 */
43
function lsx_health_plan_has_meal( $post_id = '' ) {
44
	if ( ! post_type_exists( 'meal' ) ) {
45
		return false;
46
	}
47
	if ( '' === $post_id ) {
48
		$post_id = get_the_ID();
49
	}
50
	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

50
	return \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'connected_meals' );
Loading history...
51
}
52
53
/**
54
 * Checks if the current post or supplied $post_ID has a recipes attached.
55
 *
56
 * @param string $post_id
57
 * @return boolean
58
 */
59
function lsx_health_plan_has_recipe( $post_id = '' ) {
60
	if ( ! post_type_exists( 'recipe' ) ) {
61
		return false;
62
	}
63
	if ( '' === $post_id ) {
64
		$post_id = get_the_ID();
65
	}
66
	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

66
	return \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'connected_recipes' );
Loading history...
67
}
68
69
/**
70
 * Checks if the current post or supplied $post_ID has a downloads attached.
71
 *
72
 * @param string $post_id
73
 * @return boolean
74
 */
75
function lsx_health_plan_has_downloads( $post_id = '' ) {
76
	$has_downloads = false;
77
	if ( '' === $post_id ) {
78
		$post_id = get_the_ID();
79
	}
80
	$downloads = \lsx_health_plan\functions\get_downloads( 'all', $post_id );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $downloads is correct as get_downloads('all', $post_id) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
81
	if ( ! empty( $downloads ) ) {
82
		$has_downloads = true;
83
	}
84
	return $has_downloads;
85
}
86
87
/**
88
 * Checks if the current post or supplied $post_ID has a tips attached.
89
 *
90
 * @param string $post_id
91
 * @return boolean
92
 */
93
function lsx_health_plan_has_tip( $post_id = '' ) {
94
	if ( ! post_type_exists( 'tip' ) ) {
95
		return false;
96
	}
97
	if ( '' === $post_id ) {
98
		$post_id = get_the_ID();
99
	}
100
	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

100
	return \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'connected_tips' );
Loading history...
101
}
102
103
/**
104
 * Checks if the current post or supplied $post_ID has a video attached.
105
 *
106
 * @param string $post_id
107
 * @return boolean
108
 */
109
function lsx_health_plan_has_video( $post_id = '' ) {
110
	if ( ! post_type_exists( 'video' ) ) {
111
		return false;
112
	}
113
	if ( '' === $post_id ) {
114
		$post_id = get_the_ID();
115
	}
116
	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

116
	return \lsx_health_plan\functions\has_attached_post( /** @scrutinizer ignore-type */ $post_id, 'connected_videos' );
Loading history...
117
}
118
119
/**
120
 * Checks to see if the current user has a valid purchase.
121
 *
122
 * @return boolean
123
 */
124
function lsx_health_plan_user_has_purchase() {
125
	$valid_order = false;
126
	$product_id  = \lsx_health_plan\functions\get_option( 'membership_product', false );
127
128
	if ( is_user_logged_in() && false !== $product_id ) {
129
		$current_user = wp_get_current_user();
130
		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

130
		if ( /** @scrutinizer ignore-call */ wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id ) ) {
Loading history...
131
			$valid_order = true;
132
		}
133
	}
134
	return $valid_order;
135
}
136
137
/**
138
 * Checks if the current post or supplied $post_ID has a tips attached.
139
 *
140
 * @param string $post_id
141
 * @return boolean
142
 */
143
function lsx_health_plan_is_current_tab( $needle = '' ) {
144
	$is_tab = false;
145
	$plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false );
146
	if ( false === $plan_slug ) {
147
		$plan_slug = 'my-plan';
148
	}
149
	if ( is_singular( 'plan' ) || is_page( $plan_slug ) ) {
150
		$endpoint = get_query_var( 'endpoint' );
151
		if ( false !== $endpoint && $needle === $endpoint ) {
152
			$is_tab = true;
153
		}
154
	}
155
	return $is_tab;
156
}
157
158
/**
159
 * Checks to see if the current day is complete or not
160
 *
161
 * @param string $post_id
162
 * @return boolean
163
 */
164
function lsx_health_plan_is_day_complete( $post_id = '', $section_key = '' ) {
165
	$is_complete = false;
166
	if ( '' === $post_id ) {
167
		$post_id = get_the_ID();
168
	}
169
	$key             = \lsx_health_plan\functions\plan\generate_section_id( $section_key );
170
	$is_day_complete = get_user_meta( get_current_user_id(), 'day_' . $key . '_complete', true );
171
	if ( false !== $is_day_complete && '' !== $is_day_complete ) {
172
		$is_complete = true;
173
	}
174
175
	return $is_complete;
176
}
177
178
function lsx_health_plan_is_plan_complete() {
179
	$complete = false;
180
	return $complete;
181
}
182
183
/**
184
 * Checks if the current week has any downloads attached.
185
 *
186
 * @param string $week The week name 'week-1'.
187
 * @return boolean
188
 */
189
function lsx_health_plan_week_has_downloads( $week = '' ) {
190
	$has_downloads = false;
191
	if ( '' !== $week ) {
192
		$downloads = \lsx_health_plan\functions\get_weekly_downloads( $week );
193
		if ( ! empty( $downloads ) ) {
194
			$has_downloads = true;
195
		}
196
	}
197
	return $has_downloads;
198
}
199
200
/**
201
 * Checks to see if the current ID has any tips attached.
202
 *
203
 * @param string $post_id
204
 * @return boolean
205
 */
206
function lsx_health_plan_has_tips( $post_id = '' ) {
207
	$has_tips = false;
208
	if ( '' === $post_id ) {
209
		$post_id = get_the_ID();
210
	}
211
	$connected_tips = get_post_meta( get_the_ID(), '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

211
	$connected_tips = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), 'connected_tips', true );
Loading history...
212
	$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

212
	$connected_tips = \lsx_health_plan\functions\check_posts_exist( /** @scrutinizer ignore-type */ $connected_tips );
Loading history...
Bug introduced by
Are you sure the assignment to $connected_tips is correct as check_posts_exist($connected_tips) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
213
	if ( ! empty( $connected_tips ) ) {
214
		$has_tips = true;
215
	}
216
	return $has_tips;
217
}
218