| Conditions | 3 |
| Paths | 4 |
| Total Lines | 57 |
| Code Lines | 40 |
| 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 |
||
| 34 | public function sendOrderDataToFeefo($order, $delay = 0) |
||
| 35 | { |
||
| 36 | $messages = []; |
||
| 37 | //api details |
||
| 38 | $apiKey = Config::inst()->get('EntersaleremotelyAPIConnector', 'api_key'); |
||
| 39 | $merchant = Config::inst()->get('EntersaleremotelyAPIConnector', 'merchant_identifier'); |
||
| 40 | |||
| 41 | //member specific details |
||
| 42 | $member = $order->Member(); |
||
| 43 | $email = $member->Email; |
||
| 44 | $name = $member->FirstName; |
||
| 45 | $locale = $member->Locale; |
||
| 46 | $customerRef = $member->ID; |
||
| 47 | |||
| 48 | //order specific details |
||
| 49 | $orderRef = $order->ID; |
||
| 50 | $currency = $order->CurrencyUsed()->Code; |
||
| 51 | $dateAsString = strtotime($order->Created); |
||
| 52 | $date = date('Y-m-d', $dateAsString); |
||
| 53 | |||
| 54 | $feedbackDate = ''; |
||
| 55 | if ($delay) { |
||
| 56 | $feedbackDate = date('Y-m-d', strtotime('+' . $delay . ' days', $dateAsString)); |
||
| 57 | } |
||
| 58 | |||
| 59 | foreach ($order->Items() as $orderItem) { |
||
| 60 | $amount = $orderItem->CalculatedTotal; |
||
| 61 | $product = $orderItem->Product(); |
||
| 62 | $productTitle = $product->Title; |
||
| 63 | $link = Director::absoluteURL($product->Link()); |
||
| 64 | |||
| 65 | $params = [ |
||
| 66 | 'apikey' => $apiKey, |
||
| 67 | 'merchantidentifier' => $merchant, |
||
| 68 | 'feedbackdate' => $feedbackDate, |
||
| 69 | 'email' =>$email, |
||
| 70 | 'name' => $name, |
||
| 71 | 'locale' => $locale, |
||
| 72 | 'customerref' => $customerRef, |
||
| 73 | 'orderref' => $orderRef, |
||
| 74 | 'date' => $date, |
||
| 75 | 'currency' => $currency, |
||
| 76 | 'amount ' => $orderItem->CalculatedTotal, |
||
| 77 | 'description' => $productTitle, |
||
| 78 | 'productsearchcode'=> $productTitle, |
||
| 79 | 'productlink' => $link |
||
| 80 | ]; |
||
| 81 | |||
| 82 | $result = $this->sendCurlRequest($params); |
||
| 83 | |||
| 84 | $result .= ' Order ID: ' . $orderRef . '; Product: ' . $productTitle . ';'; |
||
| 85 | |||
| 86 | array_push($messages, $result); |
||
| 87 | } |
||
| 88 | |||
| 89 | return $messages; |
||
| 90 | } |
||
| 91 | |||
| 119 |
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.