Conditions | 14 |
Paths | 10 |
Total Lines | 48 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
129 | public function index_exercises( $row ) { |
||
130 | if ( empty( $this->current_plan_ids ) ) { |
||
131 | return; |
||
132 | } |
||
133 | $i = 1; |
||
134 | $section_counter = 6; |
||
135 | $unique_connections = array(); |
||
136 | |||
137 | while ( $i <= $section_counter ) { |
||
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 ) ) { |
||
141 | foreach ( $groups as $group ) { |
||
142 | if ( isset( $group['connected_exercises'] ) && '' !== $group['connected_exercises'] ) { |
||
143 | |||
144 | if ( ! is_array( $group['connected_exercises'] ) ) { |
||
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 ) { |
||
150 | $exercise_default = $row; |
||
151 | $exercise_default['post_id'] = $eid; |
||
152 | |||
153 | foreach ( $this->current_plan_ids as $plan_id ) { |
||
154 | // Check to see if this connection has been added already. |
||
155 | if ( isset( $unique_connections[ $eid . '_' . $plan_id ] ) ) { |
||
156 | continue; |
||
157 | } |
||
158 | |||
159 | $title = get_the_title( $plan_id ); |
||
160 | if ( ! empty( $title ) ) { |
||
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 | } |
||
170 | $i++; |
||
171 | } |
||
172 | |||
173 | // If we have some unique connections, we index them. |
||
174 | if ( ! empty( $unique_connections ) ) { |
||
175 | foreach ( $unique_connections as $unique_row ) { |
||
176 | FWP()->indexer->index_row( $unique_row ); |
||
177 | } |
||
181 |