| Conditions | 16 |
| Paths | 48 |
| Total Lines | 57 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 50 | protected function setOrder() |
||
| 51 | { |
||
| 52 | /** @var ArrayData $transaction */ |
||
| 53 | $transaction = $this->getTransaction()->getParsedTransactionData()->getField('transaction'); |
||
| 54 | |||
| 55 | /** @var $order Order */ |
||
| 56 | if ($transaction->hasField('id') |
||
| 57 | && !($order = Order::get()->filter('OrderID', $transaction->getField('id'))->first())) { |
||
| 58 | $order = Order::create(); |
||
| 59 | } |
||
| 60 | |||
| 61 | if ($order->exists()) { |
||
| 62 | $this->cleanRelatedOrderData($order); |
||
| 63 | } |
||
| 64 | |||
| 65 | foreach ($this->config()->get('order_mapping') as $foxy => $ssFoxy) { |
||
| 66 | if ($transaction->hasField($foxy)) { |
||
| 67 | $order->{$ssFoxy} = $transaction->getField($foxy); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | if ($member = Member::get()->filter('Email', $order->Email)->first()) { |
||
| 72 | $order->MemberID = $member->ID; |
||
| 73 | } |
||
| 74 | |||
| 75 | $order->Response = urlencode($this->getTransaction()->getEncryptedData()); |
||
| 76 | |||
| 77 | $order->write(); |
||
| 78 | |||
| 79 | $order->Details()->addMany(OrderDetailFactory::create($this->getTransaction())->getOrderDetails()); |
||
| 80 | |||
| 81 | $this->order = Order::get()->byID($order->ID); |
||
| 82 | |||
| 83 | if ($order->Details()->count()) { |
||
| 84 | foreach ($order->Details() as $detail) { |
||
| 85 | if ($product = FoxyHelper::singleton()->getProducts()->filter('ID', $detail->ProductID)->first()) { |
||
| 86 | if ($product->hasMethod('getNumberPurchasedUpdate')) { |
||
| 87 | $product->NumberPurchased = $product->getNumberPurchasedUpdate(); |
||
| 88 | $product->write(); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | if ($detail->OrderVariations()->count()) { |
||
| 92 | foreach ($detail->OrderVariations() as $orderVariation) { |
||
| 93 | if ($orderVariation->VariationID) { |
||
| 94 | if ($variaton = Variation::get()->filter('ID', $orderVariation->VariationID)->first()) { |
||
| 95 | if ($variaton->hasMethod('getNumberPurchasedUpdate')) { |
||
| 96 | $variaton->NumberPurchased = $variaton->getNumberPurchasedUpdate(); |
||
| 97 | $variaton->write(); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return $this; |
||
| 107 | } |
||
| 117 |