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