Conditions | 49 |
Paths | > 20000 |
Total Lines | 216 |
Code Lines | 141 |
Lines | 77 |
Ratio | 35.65 % |
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 |
||
233 | protected function collateRisks() |
||
234 | { |
||
235 | $order = $this->Order(); |
||
236 | $billingAddress = $order->BillingAddress(); |
||
237 | $shippingAddress = $order->ShippingAddress(); |
||
238 | $member = $order->Member(); |
||
239 | $payments = $order->Payments(); |
||
240 | $html = ''; |
||
241 | |||
242 | $similarArray = array(); |
||
243 | |||
244 | $daysAgo = $this->Config()->get('days_ago_to_check'); |
||
245 | $timeFilter = array('Created:GreaterThan' => date('Y-m-d', strtotime('-'.$daysAgo.' days')).' 00:00:00'); |
||
246 | |||
247 | |||
248 | //check emails from user |
||
249 | $emailArray = array(); |
||
250 | if ($member) { |
||
251 | if ($member->Email) { |
||
252 | $emailArray[] = $member->Email; |
||
253 | if (OrderStatusLog_WhitelistCustomer::member_is_whitelisted($member)) { |
||
254 | $html .= '<h4 style="background-color: green; color: white; font-size: 20px; padding: 5px;">This customer is whitelisted</h4>'; |
||
255 | } else { |
||
256 | $html .= '<h4>This customer is NOT whitelisted</h4>'; |
||
257 | } |
||
258 | } |
||
259 | } |
||
260 | //are there any orders with the same Member.email in the last seven days... |
||
261 | $otherOrders = Order::get_datalist_of_orders_with_submit_record() |
||
262 | ->filter( |
||
263 | array_merge( |
||
264 | array('MemberID' => $member->ID), |
||
265 | $timeFilter |
||
266 | ) |
||
267 | ) |
||
268 | ->innerJoin('') |
||
269 | ->exclude(array('ID' => $order->ID)); |
||
270 | View Code Duplication | foreach ($otherOrders as $otherOrder) { |
|
271 | if (!isset($similarArray[$otherOrder->ID])) { |
||
272 | $similarArray[$otherOrder->ID] = array(); |
||
273 | } |
||
274 | $similarArray[$otherOrder->ID]["Email"] = $otherOrder; |
||
275 | } |
||
276 | //check emails from billing address |
||
277 | $emailArray = array(); |
||
278 | if ($billingAddress) { |
||
279 | if ($billingAddress->Email) { |
||
280 | $emailArray[] = $billingAddress->Email; |
||
281 | } |
||
282 | } |
||
283 | //are there any orders with the same Billing.Email in the last seven days... |
||
284 | $otherBillingAddresses = BillingAddress::get()->filter( |
||
285 | array('Email' => $emailArray) + $timeFilter |
||
286 | )->exclude(array('OrderID' => $order->ID)); |
||
287 | View Code Duplication | foreach ($otherBillingAddresses as $address) { |
|
288 | $otherOrder = $address->Order(); |
||
289 | if (!isset($similarArray[$otherOrder->ID])) { |
||
290 | $similarArray[$otherOrder->ID] = array(); |
||
291 | } |
||
292 | $similarArray[$otherOrder->ID]["Email"] = $otherOrder; |
||
293 | } |
||
294 | //adding all emails to security checks |
||
295 | $this->blacklistCheck($emailArray, 'EcommerceSecurityEmail'); |
||
296 | |||
297 | |||
298 | //phones |
||
299 | $phoneArray = array(); |
||
300 | if ($billingAddress) { |
||
301 | if ($billingAddress->Phone) { |
||
302 | $phoneArray[] = $billingAddress->Phone; |
||
303 | } |
||
304 | } |
||
305 | if ($shippingAddress) { |
||
306 | if ($shippingAddress->ShippingPhone) { |
||
307 | $phoneArray[] = $shippingAddress->ShippingPhone; |
||
308 | } |
||
309 | } |
||
310 | //are there any orders with the same phone in the last xxx days... |
||
311 | $otherBillingAddresses = BillingAddress::get()->filter( |
||
312 | array('Phone' => $phoneArray) + $timeFilter |
||
313 | )->exclude(array('OrderID' => $order->ID)); |
||
314 | View Code Duplication | foreach ($otherBillingAddresses as $address) { |
|
315 | $otherOrder = $address->Order(); |
||
316 | if ($otherOrder && $otherOrder->ID != $order->ID) { |
||
317 | if (!isset($similarArray[$otherOrder->ID])) { |
||
318 | $similarArray[$otherOrder->ID] = array(); |
||
319 | } |
||
320 | $similarArray[$otherOrder->ID]["Phone"] = $otherOrder; |
||
321 | } |
||
322 | } |
||
323 | $otherShippingAddresses = ShippingAddress::get()->filter( |
||
324 | array('ShippingPhone' => $phoneArray) + $timeFilter |
||
325 | )->exclude(array('OrderID' => $order->ID)); |
||
326 | View Code Duplication | foreach ($otherShippingAddresses as $address) { |
|
327 | $otherOrder = $address->Order(); |
||
328 | if ($otherOrder && $otherOrder->ID != $order->ID) { |
||
329 | if (!isset($similarArray[$otherOrder->ID])) { |
||
330 | $similarArray[$otherOrder->ID] = array(); |
||
331 | } |
||
332 | $similarArray[$otherOrder->ID]["Phone"] = $otherOrder; |
||
333 | } |
||
334 | } |
||
335 | //adding all emails to security checks |
||
336 | $this->blacklistCheck($phoneArray, 'EcommerceSecurityPhone'); |
||
337 | |||
338 | //addresses |
||
339 | $addressArray = array(); |
||
340 | if ($billingAddress) { |
||
341 | if ($billingAddress->Address) { |
||
342 | $addressArray[] = $billingAddress->Address; |
||
343 | } |
||
344 | } |
||
345 | if ($shippingAddress) { |
||
346 | if ($shippingAddress->ShippingAddress) { |
||
347 | $addressArray[] = $shippingAddress->ShippingAddress; |
||
348 | } |
||
349 | } |
||
350 | //are there any orders with the same address in the last xxx days... |
||
351 | $otherBillingAddresses = BillingAddress::get()->filter( |
||
352 | array('Address' => $addressArray) + $timeFilter |
||
353 | )->exclude(array('OrderID' => $order->ID)); |
||
354 | View Code Duplication | foreach ($otherBillingAddresses as $address) { |
|
355 | $otherOrder = $address->Order(); |
||
356 | if ($otherOrder && $otherOrder->ID != $order->ID) { |
||
357 | if (!isset($similarArray[$otherOrder->ID])) { |
||
358 | $similarArray[$otherOrder->ID] = array(); |
||
359 | } |
||
360 | $similarArray[$otherOrder->ID]["Address"] = $otherOrder; |
||
361 | } |
||
362 | } |
||
363 | $otherShippingAddresses = ShippingAddress::get() |
||
364 | ->filter( |
||
365 | array('ShippingAddress' => $addressArray) + $timeFilter |
||
366 | ) |
||
367 | ->exclude(array('OrderID' => $order->ID)); |
||
368 | View Code Duplication | foreach ($otherShippingAddresses as $address) { |
|
369 | $otherOrder = $address->Order(); |
||
370 | if ($otherOrder && $otherOrder->ID != $order->ID) { |
||
371 | if (!isset($similarArray[$otherOrder->ID])) { |
||
372 | $similarArray[$otherOrder->ID] = array(); |
||
373 | } |
||
374 | $similarArray[$otherOrder->ID]["Address"] = $otherOrder; |
||
375 | } |
||
376 | } |
||
377 | $this->blacklistCheck($addressArray, 'EcommerceSecurityAddress'); |
||
378 | |||
379 | |||
380 | //IP |
||
381 | $ipArray = array(); |
||
382 | $ipProxyArray = array(); |
||
383 | if ($payments) { |
||
384 | foreach ($payments as $payment) { |
||
385 | if(strlen($payment->IP) > 10) { |
||
386 | $ipArray[] = $payment->IP; |
||
387 | } |
||
388 | if(strlen($payment->ProxyIP) > 10) { |
||
389 | $ipProxyArray[] = $payment->ProxyIP; |
||
390 | } |
||
391 | } |
||
392 | } |
||
393 | View Code Duplication | if(count($ipArray)) { |
|
394 | //are there any orders with the same IP in the xxx seven days... |
||
395 | $otherPayments = EcommercePayment::get()->filter( |
||
396 | array('IP' => $ipArray) + $timeFilter |
||
397 | )->exclude(array('OrderID' => $order->ID)); |
||
398 | foreach ($otherPayments as $payment) { |
||
399 | $otherOrder = $payment->Order(); |
||
400 | if (!isset($similarArray[$otherOrder->ID])) { |
||
401 | $similarArray[$otherOrder->ID] = array(); |
||
402 | } |
||
403 | $similarArray[$otherOrder->ID]["IP"] = $otherOrder; |
||
404 | } |
||
405 | $this->blacklistCheck($ipArray, 'EcommerceSecurityIP'); |
||
406 | } |
||
407 | View Code Duplication | if(count($ipProxyArray)) { |
|
408 | //are there any orders with the same Proxy in the xxx seven days... |
||
409 | $otherPayments = EcommercePayment::get()->filter( |
||
410 | array('ProxyIP' => $ipProxyArray) + $timeFilter |
||
411 | )->exclude(array('OrderID' => $order->ID)); |
||
412 | foreach ($otherPayments as $payment) { |
||
413 | $otherOrder = $payment->Order(); |
||
414 | if (!isset($similarArray[$otherOrder->ID])) { |
||
415 | $similarArray[$otherOrder->ID] = array(); |
||
416 | } |
||
417 | $similarArray[$otherOrder->ID]["ProxyIP"] = $otherOrder; |
||
418 | } |
||
419 | $this->blacklistCheck($ipProxyArray, 'EcommerceSecurityProxyIP'); |
||
420 | } |
||
421 | |||
422 | |||
423 | if (count($this->warningMessages)) { |
||
424 | $html .= '<h4 style="color: red;">Blacklisted Details</h4><ul class="SecurityCheckListOfRisks warnings" style="color: red;">'; |
||
425 | foreach ($this->warningMessages as $warningMessage) { |
||
426 | $html .= $warningMessage; |
||
427 | } |
||
428 | $html .= '</ul>'; |
||
429 | } else { |
||
430 | $html .= '<h4>No Blacklisted Data Present</h4>'; |
||
431 | } |
||
432 | if (count($similarArray)) { |
||
433 | $days = $this->Config()->get('days_ago_to_check'); |
||
434 | $html .= '<h4>Similar orders in the last '.$days.' days</h4><ul class="SecurityCheckListOfRisks otherRisks">'; |
||
435 | foreach ($similarArray as $orderID => $fields) { |
||
436 | //we just loop this so we can get the order ... |
||
437 | foreach ($fields as $tempOrder) { |
||
438 | break; |
||
439 | } |
||
440 | $html .= '<li><a href="'.$tempOrder->CMSEditLink().'">'.$tempOrder->getTitle().'</a>: with same '.implode(', and with same ', array_keys($fields)).'</li>'; |
||
441 | } |
||
442 | $html .= '</ul>'; |
||
443 | } else { |
||
444 | $html .= '<p class="message good">There were no similar orders in the last '.$daysAgo.' days</p>'; |
||
445 | } |
||
446 | |||
447 | return $html; |
||
448 | } |
||
449 | |||
574 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.