| Conditions | 50 |
| Paths | > 20000 |
| Total Lines | 226 |
| Lines | 77 |
| Ratio | 34.07 % |
| 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 |
||
| 313 | protected function collateRisks() |
||
| 314 | { |
||
| 315 | $order = $this->Order(); |
||
| 316 | $billingAddress = $order->BillingAddress(); |
||
| 317 | $shippingAddress = $order->ShippingAddress(); |
||
| 318 | $member = $this->orderMember(); |
||
| 319 | $payments = $order->Payments(); |
||
| 320 | $html = ''; |
||
| 321 | |||
| 322 | $similarArray = array(); |
||
| 323 | |||
| 324 | $daysAgo = $this->Config()->get('days_ago_to_check'); |
||
| 325 | $timeFilter = array('Created:GreaterThan' => date('Y-m-d', strtotime('-'.$daysAgo.' days')).' 00:00:00'); |
||
| 326 | |||
| 327 | |||
| 328 | //check emails from user |
||
| 329 | $emailArray = array(); |
||
| 330 | if ($member) { |
||
| 331 | if ($member->Email) { |
||
| 332 | $emailArray[] = $member->Email; |
||
| 333 | if (OrderStatusLog_WhitelistCustomer::member_is_security_risk($member)) { |
||
| 334 | $html .= '<p class="message bad">This customer has been marked as a security risk.</p>'; |
||
| 335 | } else { |
||
| 336 | if (OrderStatusLog_WhitelistCustomer::member_is_whitelisted($member)) { |
||
| 337 | $html .= '<p class="warning good">This customer is whitelisted.</p>'; |
||
| 338 | } else { |
||
| 339 | $html .= '<p class="message warning">This customer is NOT whitelisted.</p>'; |
||
| 340 | } |
||
| 341 | } |
||
| 342 | } |
||
| 343 | } |
||
| 344 | //are there any orders with the same Member.email in the last seven days... |
||
| 345 | $otherOrders = Order::get_datalist_of_orders_with_submit_record() |
||
| 346 | ->filter( |
||
| 347 | array_merge( |
||
| 348 | array('MemberID' => $member->ID), |
||
| 349 | $timeFilter |
||
| 350 | ) |
||
| 351 | ) |
||
| 352 | ->exclude(array('ID' => $order->ID)); |
||
| 353 | View Code Duplication | foreach ($otherOrders as $otherOrder) { |
|
| 354 | if (!isset($similarArray[$otherOrder->ID])) { |
||
| 355 | $similarArray[$otherOrder->ID] = array(); |
||
| 356 | } |
||
| 357 | $similarArray[$otherOrder->ID]["Email"] = $otherOrder; |
||
| 358 | } |
||
| 359 | //check emails from billing address |
||
| 360 | $emailArray = array(); |
||
| 361 | if ($billingAddress) { |
||
| 362 | if ($billingAddress->Email) { |
||
| 363 | $emailArray[] = $billingAddress->Email; |
||
| 364 | } |
||
| 365 | } |
||
| 366 | //are there any orders with the same Billing.Email in the last seven days... |
||
| 367 | $otherBillingAddresses = BillingAddress::get()->filter( |
||
| 368 | array('Email' => $emailArray) + $timeFilter |
||
| 369 | )->exclude(array('OrderID' => $order->ID)); |
||
| 370 | View Code Duplication | foreach ($otherBillingAddresses as $address) { |
|
| 371 | $otherOrder = $address->Order(); |
||
| 372 | if (!isset($similarArray[$otherOrder->ID])) { |
||
| 373 | $similarArray[$otherOrder->ID] = array(); |
||
| 374 | } |
||
| 375 | $similarArray[$otherOrder->ID]["Email"] = $otherOrder; |
||
| 376 | } |
||
| 377 | //adding all emails to security checks |
||
| 378 | $this->blacklistCheck($emailArray, 'EcommerceSecurityEmail'); |
||
| 379 | |||
| 380 | |||
| 381 | //phones |
||
| 382 | $phoneArray = array(); |
||
| 383 | if ($billingAddress) { |
||
| 384 | if ($billingAddress->Phone) { |
||
| 385 | $phoneArray[] = $billingAddress->Phone; |
||
| 386 | } |
||
| 387 | } |
||
| 388 | if ($shippingAddress) { |
||
| 389 | if ($shippingAddress->ShippingPhone) { |
||
| 390 | $phoneArray[] = $shippingAddress->ShippingPhone; |
||
| 391 | } |
||
| 392 | } |
||
| 393 | //are there any orders with the same phone in the last xxx days... |
||
| 394 | $otherBillingAddresses = BillingAddress::get()->filter( |
||
| 395 | array('Phone' => $phoneArray) + $timeFilter |
||
| 396 | )->exclude(array('OrderID' => $order->ID)); |
||
| 397 | View Code Duplication | foreach ($otherBillingAddresses as $address) { |
|
| 398 | $otherOrder = $address->Order(); |
||
| 399 | if ($otherOrder && $otherOrder->ID != $order->ID) { |
||
| 400 | if (!isset($similarArray[$otherOrder->ID])) { |
||
| 401 | $similarArray[$otherOrder->ID] = array(); |
||
| 402 | } |
||
| 403 | $similarArray[$otherOrder->ID]["Phone"] = $otherOrder; |
||
| 404 | } |
||
| 405 | } |
||
| 406 | $otherShippingAddresses = ShippingAddress::get()->filter( |
||
| 407 | array('ShippingPhone' => $phoneArray) + $timeFilter |
||
| 408 | )->exclude(array('OrderID' => $order->ID)); |
||
| 409 | View Code Duplication | foreach ($otherShippingAddresses as $address) { |
|
| 410 | $otherOrder = $address->Order(); |
||
| 411 | if ($otherOrder && $otherOrder->ID != $order->ID) { |
||
| 412 | if (!isset($similarArray[$otherOrder->ID])) { |
||
| 413 | $similarArray[$otherOrder->ID] = array(); |
||
| 414 | } |
||
| 415 | $similarArray[$otherOrder->ID]["Phone"] = $otherOrder; |
||
| 416 | } |
||
| 417 | } |
||
| 418 | //adding all emails to security checks |
||
| 419 | $this->blacklistCheck($phoneArray, 'EcommerceSecurityPhone'); |
||
| 420 | |||
| 421 | //addresses |
||
| 422 | $addressArray = array(); |
||
| 423 | if ($billingAddress) { |
||
| 424 | if ($billingAddress->Address) { |
||
| 425 | $addressArray[] = $billingAddress->Address; |
||
| 426 | } |
||
| 427 | } |
||
| 428 | if ($shippingAddress) { |
||
| 429 | if ($shippingAddress->ShippingAddress) { |
||
| 430 | $addressArray[] = $shippingAddress->ShippingAddress; |
||
| 431 | } |
||
| 432 | } |
||
| 433 | //are there any orders with the same address in the last xxx days... |
||
| 434 | $otherBillingAddresses = BillingAddress::get()->filter( |
||
| 435 | array('Address' => $addressArray) + $timeFilter |
||
| 436 | )->exclude(array('OrderID' => $order->ID)); |
||
| 437 | View Code Duplication | foreach ($otherBillingAddresses as $address) { |
|
| 438 | $otherOrder = $address->Order(); |
||
| 439 | if ($otherOrder && $otherOrder->ID != $order->ID) { |
||
| 440 | if (!isset($similarArray[$otherOrder->ID])) { |
||
| 441 | $similarArray[$otherOrder->ID] = array(); |
||
| 442 | } |
||
| 443 | $similarArray[$otherOrder->ID]["Address"] = $otherOrder; |
||
| 444 | } |
||
| 445 | } |
||
| 446 | $otherShippingAddresses = ShippingAddress::get() |
||
| 447 | ->filter( |
||
| 448 | array('ShippingAddress' => $addressArray) + $timeFilter |
||
| 449 | ) |
||
| 450 | ->exclude(array('OrderID' => $order->ID)); |
||
| 451 | View Code Duplication | foreach ($otherShippingAddresses as $address) { |
|
| 452 | $otherOrder = $address->Order(); |
||
| 453 | if ($otherOrder && $otherOrder->ID != $order->ID) { |
||
| 454 | if (!isset($similarArray[$otherOrder->ID])) { |
||
| 455 | $similarArray[$otherOrder->ID] = array(); |
||
| 456 | } |
||
| 457 | $similarArray[$otherOrder->ID]["Address"] = $otherOrder; |
||
| 458 | } |
||
| 459 | } |
||
| 460 | $this->blacklistCheck($addressArray, 'EcommerceSecurityAddress'); |
||
| 461 | |||
| 462 | |||
| 463 | //IP |
||
| 464 | $ipArray = array(); |
||
| 465 | $ipProxyArray = array(); |
||
| 466 | if ($payments) { |
||
| 467 | foreach ($payments as $payment) { |
||
| 468 | if (strlen($payment->IP) > 10) { |
||
| 469 | $ipArray[] = $payment->IP; |
||
| 470 | } |
||
| 471 | if (strlen($payment->ProxyIP) > 10) { |
||
| 472 | $ipProxyArray[] = $payment->ProxyIP; |
||
| 473 | } |
||
| 474 | } |
||
| 475 | } |
||
| 476 | View Code Duplication | if (count($ipArray)) { |
|
| 477 | //are there any orders with the same IP in the xxx seven days... |
||
| 478 | $otherPayments = EcommercePayment::get()->filter( |
||
| 479 | array('IP' => $ipArray) + $timeFilter |
||
| 480 | )->exclude(array('OrderID' => $order->ID)); |
||
| 481 | foreach ($otherPayments as $payment) { |
||
| 482 | $otherOrder = $payment->Order(); |
||
| 483 | if (!isset($similarArray[$otherOrder->ID])) { |
||
| 484 | $similarArray[$otherOrder->ID] = array(); |
||
| 485 | } |
||
| 486 | $similarArray[$otherOrder->ID]["IP"] = $otherOrder; |
||
| 487 | } |
||
| 488 | $this->blacklistCheck($ipArray, 'EcommerceSecurityIP'); |
||
| 489 | } |
||
| 490 | View Code Duplication | if (count($ipProxyArray)) { |
|
| 491 | //are there any orders with the same Proxy in the xxx seven days... |
||
| 492 | $otherPayments = EcommercePayment::get()->filter( |
||
| 493 | array('ProxyIP' => $ipProxyArray) + $timeFilter |
||
| 494 | )->exclude(array('OrderID' => $order->ID)); |
||
| 495 | foreach ($otherPayments as $payment) { |
||
| 496 | $otherOrder = $payment->Order(); |
||
| 497 | if (!isset($similarArray[$otherOrder->ID])) { |
||
| 498 | $similarArray[$otherOrder->ID] = array(); |
||
| 499 | } |
||
| 500 | $similarArray[$otherOrder->ID]["ProxyIP"] = $otherOrder; |
||
| 501 | } |
||
| 502 | $this->blacklistCheck($ipProxyArray, 'EcommerceSecurityProxyIP'); |
||
| 503 | } |
||
| 504 | |||
| 505 | |||
| 506 | if (count($this->warningMessages)) { |
||
| 507 | $html .= ' |
||
| 508 | <h4 style="color: red;">Blacklisted Details</h4> |
||
| 509 | <ul class="SecurityCheckListOfRisks warnings" style="color: red;">'; |
||
| 510 | foreach ($this->warningMessages as $warningMessage) { |
||
| 511 | $html .= $warningMessage; |
||
| 512 | } |
||
| 513 | $html .= ' |
||
| 514 | </ul>'; |
||
| 515 | } else { |
||
| 516 | $html .= '<p class="message good">No Blacklisted Data Present</p>'; |
||
| 517 | } |
||
| 518 | if (count($similarArray)) { |
||
| 519 | $days = $this->Config()->get('days_ago_to_check'); |
||
| 520 | $html .= ' |
||
| 521 | <h4>Similar orders in the last '.$days.' days</h4> |
||
| 522 | <ul class="SecurityCheckListOfRisks otherRisks">'; |
||
| 523 | foreach ($similarArray as $orderID => $fields) { |
||
| 524 | //we just loop this so we can get the order ... |
||
| 525 | foreach ($fields as $tempOrder) { |
||
| 526 | break; |
||
| 527 | } |
||
| 528 | $html .= ' |
||
| 529 | <li><a href="'.$tempOrder->CMSEditLink().'">'.$tempOrder->getTitle().'</a>: with same '.implode(', and with same ', array_keys($fields)).'</li>'; |
||
| 530 | } |
||
| 531 | $html .= ' |
||
| 532 | </ul>'; |
||
| 533 | } else { |
||
| 534 | $html .= '<p class="message good">No similar orders in the last '.$daysAgo.' days</p>'; |
||
| 535 | } |
||
| 536 | |||
| 537 | return $html; |
||
| 538 | } |
||
| 539 | |||
| 679 |
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.