Conditions | 15 |
Paths | 10 |
Total Lines | 104 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |
||
156 | private function generateSubsections(): array |
||
157 | { |
||
158 | // Init reg forms count. |
||
159 | $this->reg_form_count = 0; |
||
160 | |||
161 | $primary_registrant = null; |
||
162 | // autoload Line_Item_Display classes |
||
163 | EEH_Autoloader::register_line_item_display_autoloaders(); |
||
164 | $Line_Item_Display = new EE_Line_Item_Display(); |
||
165 | // calculate taxes |
||
166 | $Line_Item_Display->display_line_item( |
||
167 | $this->reg_step->checkout->cart->get_grand_total(), |
||
168 | ['set_tax_rate' => true] |
||
169 | ); |
||
170 | $extra_inputs_section = $this->reg_step->reg_step_hidden_inputs(); |
||
171 | $this->addPrivacyConsentCheckbox($extra_inputs_section); |
||
172 | $subsections = [ |
||
173 | 'default_hidden_inputs' => $extra_inputs_section, |
||
174 | ]; |
||
175 | |||
176 | $this->template_args = [ |
||
177 | 'revisit' => $this->reg_step->checkout->revisit, |
||
178 | 'registrations' => [], |
||
179 | 'ticket_count' => [], |
||
180 | ]; |
||
181 | // grab the saved registrations from the transaction |
||
182 | $registrations = $this->reg_step->checkout->transaction->registrations( |
||
183 | $this->reg_step->checkout->reg_cache_where_params |
||
184 | ); |
||
185 | if ($registrations) { |
||
|
|||
186 | foreach ($registrations as $registration) { |
||
187 | // can this registration be processed during this visit ? |
||
188 | if ( |
||
189 | $registration instanceof EE_Registration |
||
190 | && $this->reg_step->checkout->visit_allows_processing_of_this_registration($registration) |
||
191 | ) { |
||
192 | $reg_url_link = $registration->reg_url_link(); |
||
193 | /** @var RegistrantForm $registrant_form */ |
||
194 | $registrant_form = LoaderFactory::getNew( |
||
195 | RegistrantForm::class, |
||
196 | [ |
||
197 | $registration, |
||
198 | $this->reg_step->checkout->admin_request, |
||
199 | $this->reg_config->copyAttendeeInfo(), |
||
200 | [$this, 'enablePrintCopyInfo'], |
||
201 | ] |
||
202 | ); |
||
203 | // Increment the reg forms number if form is valid. |
||
204 | if ($registrant_form->hasQuestions()) { |
||
205 | $this->reg_form_count++; |
||
206 | $subsections[ $reg_url_link ] = $registrant_form; |
||
207 | } else { |
||
208 | // or just add a blank section if there are no questions |
||
209 | $subsections[ $reg_url_link ] = new EE_Form_Section_HTML(); |
||
210 | } |
||
211 | |||
212 | $this->template_args['registrations'][ $reg_url_link ] = $registration; |
||
213 | $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
||
214 | $this->template_args['ticket_count'][ $registration->ticket()->ID() ] |
||
215 | ) |
||
216 | ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
||
217 | : 1; |
||
218 | $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
||
219 | $this->reg_step->checkout->cart->get_grand_total(), |
||
220 | 'Ticket', |
||
221 | [$registration->ticket()->ID()] |
||
222 | ); |
||
223 | $ticket_line_item = is_array($ticket_line_item) |
||
224 | ? reset($ticket_line_item) |
||
225 | : $ticket_line_item; |
||
226 | $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
||
227 | $Line_Item_Display->display_line_item($ticket_line_item); |
||
228 | if ($registration->is_primary_registrant()) { |
||
229 | $primary_registrant = $reg_url_link; |
||
230 | } |
||
231 | } |
||
232 | } |
||
233 | |||
234 | if ($primary_registrant && count($registrations) > 1) { |
||
235 | if ( |
||
236 | isset($subsections[ $primary_registrant ]) |
||
237 | && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
||
238 | ) { |
||
239 | $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info |
||
240 | ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug()) |
||
241 | : new AutoCopyAttendeeInfoForm($this->reg_step->slug()); |
||
242 | $subsections[ $primary_registrant ]->add_subsections( |
||
243 | $copy_options, |
||
244 | 'primary_registrant', |
||
245 | false |
||
246 | ); |
||
247 | } |
||
248 | } |
||
249 | } |
||
250 | |||
251 | // Set the registration form template (default: one form per ticket details table). |
||
252 | // We decide the template to used based on the number of forms. |
||
253 | $template = $this->reg_form_count > 1 |
||
254 | ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php' |
||
255 | : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php'; |
||
256 | $this->reg_step->setTemplate($template); |
||
257 | |||
258 | return $subsections; |
||
259 | } |
||
260 | |||
283 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.