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