Issues (4138)

includes/functions/plan.php (66 issues)

1
<?php
2
/**
3
 * LSX Health Plan Plan specific functions.
4
 *
5
 * @package lsx-health-plan
6
 */
7
8
namespace lsx_health_plan\functions\plan;
9
10
/**
11
 * Return a true or false if the search is enabled.
12
 *
13
 * @return boolean
14
 */
15
function is_search_enabled() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
16
	$enabled = false;
17
	if ( function_exists( 'lsx_search' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
18
		$search_instance = \LSX_Search::get_instance();
0 ignored issues
show
The type LSX_Search was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
		if ( null !== $search_instance ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
20
			$enabled = $search_instance->frontend->is_search_enabled();
21
		}
22
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
23
	return $enabled;
24
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
25
26
/**
27
 * Return a true or false if the search if the plan has sections.
28
 *
29
 * @param  integer $plan_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
30
 * @return boolean
31
 */
32
function has_sections( $plan_id = 0 ) {
33
	$sections = false;
34
	if ( 0 === $plan_id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
35
		$plan_id = get_the_ID();
36
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
37
	$lsx_hp   = lsx_health_plan();
38
	$sections = $lsx_hp->frontend->plan_query->query_sections( $plan_id );
39
	return $sections;
40
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
41
42
/**
43
 * Returns the sections for a plan
44
 *
45
 * @param  integer $plan_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Doc comment for parameter $plan_id does not match actual variable name $group_sections
Loading history...
46
 * @param  boolean $group_sections
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Superfluous parameter comment
Loading history...
47
 * @return array
48
 */
49
function get_sections( $group_sections = false ) {
50
	$lsx_hp   = lsx_health_plan();
51
	$sections = $lsx_hp->frontend->plan_query->get_sections( $group_sections );
52
	return $sections;
53
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
54
55
/**
56
 * Gets the current sections array values.
57
 *
58
 * @param  string $section_key
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
59
 * @return array
60
 */
61
function get_section_info( $section_key = '' ) {
62
	$section_info = array();
63
64
	$sections = get_sections();
65
	if ( ! empty( $sections ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
66
		foreach ( $sections as $key => $values ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
67
			$current_key = sanitize_title( $values['title'] );
68
			if ( $current_key === $section_key ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
69
				return $values;
70
			}
71
		}
72
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
73
	return $section_info;
74
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
75
76
/**
77
 * This will group title from the first section item.
78
 *
79
 * @param  array $sections
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
80
 * @return array
81
 */
82
function get_group_title( $sections = array() ) {
83
	$group_title = apply_filters( 'lsx_hp_default_plan_group', __( 'Daily Plan', 'lsx-health-plan' ) );
84
	if ( ! empty( $sections ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
85
		$first_section = reset( $sections );
86
		if ( isset( $first_section['group'] ) && '' !== $first_section['group'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
87
			$group_title = $first_section['group'];
88
		}
89
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
90
	return $group_title;
91
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
92
93
/**
94
 * Returns the sections for a plan
95
 *
96
 * @param  integer $plan_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
97
 * @param  string  $title
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
98
 * @return array
99
 */
100
function get_permalink( $plan_id = 0, $title = '' ) {
101
	if ( 0 === $plan_id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
102
		$plan_id = get_the_ID();
103
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
104
	$url = \get_permalink( $plan_id );
0 ignored issues
show
It seems like $plan_id can also be of type false; however, parameter $post of get_permalink() does only seem to accept WP_Post|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

104
	$url = \get_permalink( /** @scrutinizer ignore-type */ $plan_id );
Loading history...
105
	if ( '' !== $title ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
106
		$url .= sanitize_title( $title ) . '/';
107
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
108
	return $url;
109
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
110
111
/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$disabled" missing
Loading history...
112
 * Return a true or false if the search is enabled.
113
 *
114
 * @return boolean
115
 */
116
function is_filters_disabled( $disabled = false ) {
117
	$is_disabled = \lsx_health_plan\functions\get_option( 'plan_filters_disabled', false );
118
	if ( false !== $is_disabled ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
119
		$disabled = true;
120
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
121
	return $disabled;
122
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
123
124
/**
125
 * Generates a unique ID for the current section item you are viewing,  e.g Day 1 of Week 1.
126
 * Can only be used on the single plan pages and endpoints.
127
 *
128
 * @param  string  $section_key
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Expected 1 spaces after parameter type; 2 found
Loading history...
129
 * @return string
130
 */
131
function generate_section_id( $section_key = '' ) {
132
	$key          = get_the_ID();
0 ignored issues
show
Equals sign not aligned correctly; expected 1 space but found 10 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

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

will have no issues, while

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

will report issues in lines 1 and 2.

Loading history...
133
	if ( '' === $section_key ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
134
		$section_key  = get_query_var( 'section' );
0 ignored issues
show
Equals sign not aligned correctly; expected 1 space but found 2 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

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

will have no issues, while

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

will report issues in lines 1 and 2.

Loading history...
135
	}
136
137
	$section_key = sanitize_title( $section_key );
138
	
139
	if ( '' !== $section_key && \lsx_health_plan\functions\plan\has_sections() ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
140
		$group_title  = apply_filters( 'lsx_hp_default_plan_group', __( 'Daily Plan', 'lsx-health-plan' ) );
141
		$section_info = \lsx_health_plan\functions\plan\get_section_info( $section_key );
142
		$key         .= '_' . sanitize_key( $group_title ) . '_' . sanitize_key( $section_info['title'] );
143
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
144
	return $key;
145
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
146