Conditions | 15 |
Paths | 1537 |
Total Lines | 110 |
Code Lines | 74 |
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 |
||
126 | public function process_booking( $bookingInfo = null ) { |
||
127 | if ( isset( $_POST['act'] ) && 'bookCourse' === $_POST['act'] ) { |
||
128 | $bookingInfo->NoRedirect = true; |
||
129 | |||
130 | $countries = EDU()->api->GetCountries( EDU()->get_token(), 'Swedish' ); |
||
131 | |||
132 | $selectedCountry = 'SE'; |
||
133 | $selectedLocale = 'sv-SE'; |
||
134 | |||
135 | $invoiceCountry = $bookingInfo->Customer->InvoiceCountry; |
||
136 | if ( empty( $invoiceCountry ) ) { |
||
137 | $invoiceCountry = $bookingInfo->Customer->Country; |
||
138 | } |
||
139 | |||
140 | foreach ( $countries as $country ) { |
||
141 | if ( $invoiceCountry == $country->CountryName ) { |
||
142 | $selectedCountry = $country->CountryCode; |
||
143 | if ( ! empty( $country->CultureName ) ) { |
||
144 | $selectedLocale = $country->CultureName; |
||
145 | } |
||
146 | break; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | $selectedLocale = explode( '-', $selectedLocale )[0]; |
||
151 | |||
152 | $currency = get_option( 'eduadmin-currency', 'SEK' ); |
||
153 | |||
154 | $wpConfig = ConfigurationService::getDefaultConfig(); |
||
155 | $wpOrder = WebPay::createOrder( $wpConfig ); |
||
156 | |||
157 | $orderRow = WebPayItem::orderRow(); |
||
158 | $orderRow->setName( $bookingInfo->EventBooking->EventDescription ); |
||
159 | $orderRow->setQuantity( 1 ); |
||
160 | |||
161 | $vatPercent = ( $bookingInfo->EventBooking->VatSum / $bookingInfo->EventBooking->TotalPriceExVat ) * 100; |
||
162 | $orderRow->setVatPercent( $vatPercent ); |
||
163 | $orderRow->setAmountIncVat( (float) $bookingInfo->EventBooking->TotalPriceIncVat ); |
||
164 | |||
165 | $customer = WebPayItem::companyCustomer(); |
||
166 | |||
167 | if ( ! empty( $bookingInfo->Customer->InvoiceName ) ) { |
||
168 | $customer->setCompanyName( $bookingInfo->Customer->InvoiceName ); |
||
169 | } else { |
||
170 | $customer->setCompanyName( $bookingInfo->Customer->CustomerName ); |
||
171 | } |
||
172 | |||
173 | if ( ! empty( $bookingInfo->Customer->InvoiceAddress1 ) ) { |
||
174 | $customer->setStreetAddress( $bookingInfo->Customer->InvoiceAddress1 ); |
||
175 | } else { |
||
176 | $customer->setStreetAddress( $bookingInfo->Customer->Address1 ); |
||
177 | } |
||
178 | |||
179 | if ( ! empty( $bookingInfo->Customer->InvoiceZip ) ) { |
||
180 | $customer->setZipCode( $bookingInfo->Customer->InvoiceZip ); |
||
181 | } else { |
||
182 | $customer->setZipCode( $bookingInfo->Customer->Zip ); |
||
183 | } |
||
184 | |||
185 | if ( ! empty( $bookingInfo->Customer->InvoiceCity ) ) { |
||
186 | $customer->setLocality( $bookingInfo->Customer->InvoiceCity ); |
||
187 | } else { |
||
188 | $customer->setLocality( $bookingInfo->Customer->City ); |
||
189 | } |
||
190 | |||
191 | if ( ! empty( $bookingInfo->Customer->Phone ) ) { |
||
192 | $customer->setPhoneNumber( $bookingInfo->Customer->Phone ); |
||
193 | } |
||
194 | |||
195 | if ( ! empty( $bookingInfo->Customer->InvoiceEmail ) ) { |
||
196 | $customer->setEmail( $bookingInfo->Customer->InvoiceEmail ); |
||
197 | } else { |
||
198 | $customer->setEmail( $bookingInfo->Customer->Email ); |
||
199 | } |
||
200 | |||
201 | $customer->setIpAddress( EDU()->get_ip_adress() ); |
||
202 | |||
203 | $surl = get_home_url(); |
||
204 | $cat = get_option( 'eduadmin-rewriteBaseUrl' ); |
||
205 | $baseUrl = $surl . '/' . $cat; |
||
206 | |||
207 | $defaultThankYou = @get_page_link( get_option( 'eduadmin-thankYouPage', '/' ) ) . "?edu-thankyou=" . $bookingInfo->EventBooking->EventCustomerLnkID . '&svea=1'; |
||
208 | $defaultCancel = $baseUrl . "?edu-cancel=" . $bookingInfo->EventBooking->EventCustomerLnkID . '&svea=1'; |
||
209 | |||
210 | $wpForm = $wpOrder |
||
211 | ->setCurrency( $currency ) |
||
212 | ->setCountryCode( $selectedCountry ) |
||
213 | ->setOrderDate( date( 'c' ) ) |
||
214 | ->setClientOrderNumber( $bookingInfo->EventBooking->EventCustomerLnkID ) |
||
215 | ->addOrderRow( $orderRow ) |
||
216 | ->addCustomerDetails( $customer ) |
||
217 | ->usePayPage() |
||
218 | ->setPayPageLanguage( $selectedLocale ) |
||
219 | ->setReturnUrl( apply_filters( 'eduadmin-thankyou-url', $defaultThankYou ) ) |
||
220 | ->setCancelUrl( apply_filters( 'eduadmin-cancel-url', $defaultCancel ) ) |
||
221 | ->getPaymentUrl(); |
||
222 | |||
223 | if ( $wpForm->accepted ) { |
||
224 | if ( 'no' === $this->get_option( 'testrun', 'no' ) ) { |
||
225 | echo '<script type="text/javascript">location.href = "' . $wpForm->url . '";</script>'; |
||
226 | } else { |
||
227 | echo '<script type="text/javascript">location.href = "' . $wpForm->testurl . '";</script>'; |
||
228 | } |
||
229 | } else { |
||
230 | add_filter( 'edu-booking-error', function( $errors ) use ( &$wpForm ) { |
||
231 | $errors[] = $wpForm->errormessage; |
||
232 | } ); |
||
233 | } |
||
234 | } |
||
235 | } |
||
236 | } |
||
238 | endif; |