1 | <?php |
||||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||||
2 | namespace lsx_health_plan\classes\integrations\facetwp; |
||||||
3 | |||||||
4 | /** |
||||||
5 | * Contains the downloads functions post type |
||||||
6 | * |
||||||
7 | * @package lsx-health-plan |
||||||
8 | */ |
||||||
9 | class Connected_Plans { |
||||||
10 | |||||||
11 | /** |
||||||
12 | * Holds class instance |
||||||
13 | * |
||||||
14 | * @since 1.0.0 |
||||||
15 | * |
||||||
16 | * @var object \lsx_health_plan\classes\integrations\facetwp\Connected_Plans() |
||||||
17 | */ |
||||||
18 | protected static $instance = null; |
||||||
19 | |||||||
20 | /** |
||||||
21 | * This hold the current plan IDS, in case they need to be used in additional functions. |
||||||
22 | * |
||||||
23 | * @var array |
||||||
24 | */ |
||||||
25 | public $current_plan_ids = array(); |
||||||
26 | |||||||
27 | /** |
||||||
28 | * Constructor |
||||||
29 | */ |
||||||
30 | public function __construct() { |
||||||
0 ignored issues
–
show
|
|||||||
31 | //add_filter( 'facetwp_index_row', array( $this, 'facetwp_index_row' ), 10, 2 ); |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
62% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||||
32 | add_filter( 'facetwp_indexer_post_facet', array( $this, 'facetwp_indexer_post_facet' ), 10, 2 ); |
||||||
33 | } |
||||||
0 ignored issues
–
show
|
|||||||
34 | |||||||
35 | /** |
||||||
36 | * Return an instance of this class. |
||||||
37 | * |
||||||
38 | * @since 1.0.0 |
||||||
39 | * |
||||||
40 | * @return object \lsx_health_plan\classes\integration\facetwp\Connected_Plans() A single instance of this class. |
||||||
41 | */ |
||||||
42 | public static function get_instance() { |
||||||
43 | // If the single instance hasn't been set, set it now. |
||||||
44 | if ( null === self::$instance ) { |
||||||
0 ignored issues
–
show
|
|||||||
45 | self::$instance = new self(); |
||||||
46 | } |
||||||
0 ignored issues
–
show
|
|||||||
47 | return self::$instance; |
||||||
48 | } |
||||||
0 ignored issues
–
show
|
|||||||
49 | |||||||
50 | /** |
||||||
51 | * Index the connected plan |
||||||
52 | * |
||||||
53 | * @param array $return |
||||||
0 ignored issues
–
show
|
|||||||
54 | * @param array $params |
||||||
0 ignored issues
–
show
|
|||||||
55 | * @return array |
||||||
56 | */ |
||||||
57 | public function facetwp_indexer_post_facet( $return, $params ) { |
||||||
58 | $facet = $params['facet']; |
||||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 4 spaces
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. ![]() |
|||||||
59 | $source = isset( $facet['source'] ) ? $facet['source'] : ''; |
||||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 1 space but found 3 spaces
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. ![]() |
|||||||
60 | |||||||
61 | if ( 'lsx_hp/connected_plans' === $source ) { |
||||||
0 ignored issues
–
show
|
|||||||
62 | $post_type = get_post_type( $params['defaults']['post_id'] ); |
||||||
63 | switch ( $post_type ) { |
||||||
0 ignored issues
–
show
|
|||||||
64 | case 'workout': |
||||||
65 | $return = $this->index_connected_plans( $params['defaults'] ); |
||||||
66 | $this->index_exercises( $params['defaults'] ); |
||||||
67 | break; |
||||||
68 | |||||||
69 | case 'recipe': |
||||||
70 | $return = $this->index_connected_plans( $params['defaults'] ); |
||||||
71 | break; |
||||||
72 | |||||||
73 | case 'meal': |
||||||
74 | $return = $this->index_connected_plans( $params['defaults'] ); |
||||||
75 | break; |
||||||
76 | |||||||
77 | default: |
||||||
78 | break; |
||||||
79 | } |
||||||
80 | } |
||||||
81 | |||||||
82 | // Reset the current plan ids array. |
||||||
83 | $this->current_plan_ids = array(); |
||||||
84 | return $return; |
||||||
85 | } |
||||||
0 ignored issues
–
show
|
|||||||
86 | |||||||
87 | /** |
||||||
0 ignored issues
–
show
|
|||||||
88 | * Adds the connected plan to the list of rows. |
||||||
89 | * |
||||||
90 | * @param array $rows |
||||||
0 ignored issues
–
show
|
|||||||
91 | * @param array $params |
||||||
0 ignored issues
–
show
|
|||||||
92 | * @return boolean |
||||||
93 | */ |
||||||
94 | public function index_connected_plans( $row ) { |
||||||
95 | $indexed = false; |
||||||
96 | $top_level_plans = array(); |
||||||
97 | // Get meals this exercise is connected to. |
||||||
98 | $plans = get_post_meta( $row['post_id'], 'connected_plans', true ); |
||||||
99 | |||||||
100 | if ( ! empty( $plans ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
101 | $plan = end( $plans ); |
||||||
0 ignored issues
–
show
It seems like
$plans can also be of type string ; however, parameter $array of end() does only seem to accept array|object , 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
![]() |
|||||||
102 | $has_parent = wp_get_post_parent_id( $plan ); |
||||||
103 | if ( 0 === $has_parent ) { |
||||||
0 ignored issues
–
show
|
|||||||
104 | $top_level_plans[] = $plan; |
||||||
105 | } elseif ( false !== $top_level_plans ) { |
||||||
0 ignored issues
–
show
|
|||||||
106 | $top_level_plans[] = $has_parent; |
||||||
107 | } |
||||||
108 | } |
||||||
0 ignored issues
–
show
|
|||||||
109 | if ( ! empty( $top_level_plans ) && ( '' !== $top_level_plans ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
110 | $top_level_plans = array_unique( $top_level_plans ); |
||||||
111 | $this->current_plan_ids = $top_level_plans; |
||||||
112 | $indexed = true; |
||||||
113 | foreach ( $top_level_plans as $plan_id ) { |
||||||
0 ignored issues
–
show
|
|||||||
114 | $row['facet_value'] = $plan_id; |
||||||
115 | $row['facet_display_value'] = get_the_title( $plan_id ); |
||||||
116 | FWP()->indexer->index_row( $row ); |
||||||
0 ignored issues
–
show
The function
FWP 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
![]() |
|||||||
117 | } |
||||||
118 | } |
||||||
0 ignored issues
–
show
|
|||||||
119 | return $indexed; |
||||||
120 | } |
||||||
0 ignored issues
–
show
|
|||||||
121 | |||||||
122 | /** |
||||||
0 ignored issues
–
show
|
|||||||
123 | * We index the exercises from the workouts. |
||||||
124 | * |
||||||
125 | * @param array $rows |
||||||
0 ignored issues
–
show
|
|||||||
126 | * @param array $params |
||||||
0 ignored issues
–
show
|
|||||||
127 | * @return void |
||||||
128 | */ |
||||||
129 | public function index_exercises( $row ) { |
||||||
130 | if ( empty( $this->current_plan_ids ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
131 | return; |
||||||
132 | } |
||||||
0 ignored issues
–
show
|
|||||||
133 | $i = 1; |
||||||
134 | $section_counter = 6; |
||||||
135 | $unique_connections = array(); |
||||||
136 | |||||||
137 | while ( $i <= $section_counter ) { |
||||||
0 ignored issues
–
show
|
|||||||
138 | // Here we grab the exercises and we add them to the index with the plan IDS. |
||||||
139 | $groups = get_post_meta( $row['post_id'], 'workout_section_' . $i, true ); |
||||||
140 | if ( ! empty( $groups ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
141 | foreach ( $groups as $group ) { |
||||||
0 ignored issues
–
show
|
|||||||
142 | if ( isset( $group['connected_exercises'] ) && '' !== $group['connected_exercises'] ) { |
||||||
0 ignored issues
–
show
|
|||||||
143 | |||||||
144 | if ( ! is_array( $group['connected_exercises'] ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
145 | $group['connected_exercises'] = array( $group['connected_exercises'] ); |
||||||
146 | } |
||||||
147 | |||||||
148 | // Loop through each exercise and add it to the plan. |
||||||
149 | foreach ( $group['connected_exercises'] as $eid ) { |
||||||
0 ignored issues
–
show
|
|||||||
150 | $exercise_default = $row; |
||||||
151 | $exercise_default['post_id'] = $eid; |
||||||
152 | |||||||
153 | foreach ( $this->current_plan_ids as $plan_id ) { |
||||||
0 ignored issues
–
show
|
|||||||
154 | // Check to see if this connection has been added already. |
||||||
155 | if ( isset( $unique_connections[ $eid . '_' . $plan_id ] ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
156 | continue; |
||||||
157 | } |
||||||
158 | |||||||
159 | $title = get_the_title( $plan_id ); |
||||||
160 | if ( ! empty( $title ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
161 | $exercise_default['facet_value'] = $plan_id; |
||||||
162 | $exercise_default['facet_display_value'] = $title; |
||||||
163 | $unique_connections[ $eid . '_' . $plan_id ] = $exercise_default; |
||||||
164 | } |
||||||
165 | } |
||||||
166 | } |
||||||
167 | } |
||||||
168 | } |
||||||
169 | } |
||||||
0 ignored issues
–
show
|
|||||||
170 | $i++; |
||||||
171 | } |
||||||
172 | |||||||
173 | // If we have some unique connections, we index them. |
||||||
174 | if ( ! empty( $unique_connections ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
175 | foreach ( $unique_connections as $unique_row ) { |
||||||
0 ignored issues
–
show
|
|||||||
176 | FWP()->indexer->index_row( $unique_row ); |
||||||
0 ignored issues
–
show
The function
FWP 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
![]() |
|||||||
177 | } |
||||||
178 | } |
||||||
179 | } |
||||||
0 ignored issues
–
show
|
|||||||
180 | } |
||||||
181 |