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
Coding Style
introduced
by
![]() |
|||||
16 | $enabled = false; |
||||
17 | if ( function_exists( 'lsx_search' ) ) { |
||||
0 ignored issues
–
show
|
|||||
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
19 | if ( null !== $search_instance ) { |
||||
0 ignored issues
–
show
|
|||||
20 | $enabled = $search_instance->frontend->is_search_enabled(); |
||||
21 | } |
||||
22 | } |
||||
0 ignored issues
–
show
|
|||||
23 | return $enabled; |
||||
24 | } |
||||
0 ignored issues
–
show
|
|||||
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
|
|||||
30 | * @return boolean |
||||
31 | */ |
||||
32 | function has_sections( $plan_id = 0 ) { |
||||
33 | $sections = false; |
||||
34 | if ( 0 === $plan_id ) { |
||||
0 ignored issues
–
show
|
|||||
35 | $plan_id = get_the_ID(); |
||||
36 | } |
||||
0 ignored issues
–
show
|
|||||
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
|
|||||
41 | |||||
42 | /** |
||||
43 | * Returns the sections for a plan |
||||
44 | * |
||||
45 | * @param integer $plan_id |
||||
0 ignored issues
–
show
|
|||||
46 | * @param boolean $group_sections |
||||
0 ignored issues
–
show
|
|||||
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
|
|||||
54 | |||||
55 | /** |
||||
56 | * Gets the current sections array values. |
||||
57 | * |
||||
58 | * @param string $section_key |
||||
0 ignored issues
–
show
|
|||||
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
|
|||||
66 | foreach ( $sections as $key => $values ) { |
||||
0 ignored issues
–
show
|
|||||
67 | $current_key = sanitize_title( $values['title'] ); |
||||
68 | if ( $current_key === $section_key ) { |
||||
0 ignored issues
–
show
|
|||||
69 | return $values; |
||||
70 | } |
||||
71 | } |
||||
72 | } |
||||
0 ignored issues
–
show
|
|||||
73 | return $section_info; |
||||
74 | } |
||||
0 ignored issues
–
show
|
|||||
75 | |||||
76 | /** |
||||
77 | * This will group title from the first section item. |
||||
78 | * |
||||
79 | * @param array $sections |
||||
0 ignored issues
–
show
|
|||||
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
|
|||||
85 | $first_section = reset( $sections ); |
||||
86 | if ( isset( $first_section['group'] ) && '' !== $first_section['group'] ) { |
||||
0 ignored issues
–
show
|
|||||
87 | $group_title = $first_section['group']; |
||||
88 | } |
||||
89 | } |
||||
0 ignored issues
–
show
|
|||||
90 | return $group_title; |
||||
91 | } |
||||
0 ignored issues
–
show
|
|||||
92 | |||||
93 | /** |
||||
94 | * Returns the sections for a plan |
||||
95 | * |
||||
96 | * @param integer $plan_id |
||||
0 ignored issues
–
show
|
|||||
97 | * @param string $title |
||||
0 ignored issues
–
show
|
|||||
98 | * @return array |
||||
99 | */ |
||||
100 | function get_permalink( $plan_id = 0, $title = '' ) { |
||||
101 | if ( 0 === $plan_id ) { |
||||
0 ignored issues
–
show
|
|||||
102 | $plan_id = get_the_ID(); |
||||
103 | } |
||||
0 ignored issues
–
show
|
|||||
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
![]() |
|||||
105 | if ( '' !== $title ) { |
||||
0 ignored issues
–
show
|
|||||
106 | $url .= sanitize_title( $title ) . '/'; |
||||
107 | } |
||||
0 ignored issues
–
show
|
|||||
108 | return $url; |
||||
109 | } |
||||
0 ignored issues
–
show
|
|||||
110 | |||||
111 | /** |
||||
0 ignored issues
–
show
|
|||||
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
|
|||||
119 | $disabled = true; |
||||
120 | } |
||||
0 ignored issues
–
show
|
|||||
121 | return $disabled; |
||||
122 | } |
||||
0 ignored issues
–
show
|
|||||
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
|
|||||
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. ![]() |
|||||
133 | if ( '' === $section_key ) { |
||||
0 ignored issues
–
show
|
|||||
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. ![]() |
|||||
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
|
|||||
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
|
|||||
144 | return $key; |
||||
145 | } |
||||
0 ignored issues
–
show
|
|||||
146 |