| Conditions | 7 |
| Paths | 36 |
| Total Lines | 59 |
| Code Lines | 39 |
| 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 declare(strict_types=1); |
||
| 66 | public function addPosition(string $key, array $customParams = []): self |
||
| 67 | { |
||
| 68 | if (\array_key_exists('amount', $customParams)) { |
||
| 69 | if (\is_float($customParams['amount'])) { |
||
| 70 | $customParams['amount'] = new CalculatedPrice( |
||
| 71 | $customParams['amount'], |
||
| 72 | $customParams['amount'], |
||
| 73 | new CalculatedTaxCollection(), |
||
| 74 | new TaxRuleCollection() |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | $lineItem = []; |
||
| 80 | |||
| 81 | // if orderLineItem is not submitted, create a orderLineItem on the fly |
||
| 82 | if (!\array_key_exists('orderLineItem', $customParams)) { |
||
| 83 | $lineItem = ['orderLineItem' => (new ProductBuilder($this->ids, '10000'))->build()]; |
||
| 84 | $lineItem['orderLineItem']['identifier'] = $this->ids->get('10000'); |
||
| 85 | $lineItem['orderLineItem']['quantity'] = 1; |
||
| 86 | $lineItem['orderLineItem']['label'] = 'foo'; |
||
| 87 | $lineItem['orderLineItem']['price'] = new CalculatedPrice( |
||
| 88 | 420.69, |
||
| 89 | 420.69, |
||
| 90 | new CalculatedTaxCollection(), |
||
| 91 | new TaxRuleCollection() |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | |||
| 95 | $orderLineItemId = null; |
||
| 96 | |||
| 97 | if (\array_key_exists('orderLineItem', $lineItem)) { |
||
| 98 | if (\array_key_exists('id', $lineItem['orderLineItem'])) { |
||
| 99 | $orderLineItemId = $lineItem['orderLineItem']['id']; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | if (\array_key_exists('orderLineItem', $customParams)) { |
||
| 104 | $orderLineItemId = $customParams['orderLineItem']; |
||
| 105 | } |
||
| 106 | |||
| 107 | $position = \array_replace([ |
||
| 108 | 'refundId' => $this->id, |
||
| 109 | 'orderLineItemId' => $orderLineItemId, |
||
| 110 | 'quantity' => 1, |
||
| 111 | 'reason' => null, |
||
| 112 | 'refundPrice' => 420.69, |
||
| 113 | 'amount' => new CalculatedPrice( |
||
| 114 | 420.69, |
||
| 115 | 420.69, |
||
| 116 | new CalculatedTaxCollection(), |
||
| 117 | new TaxRuleCollection() |
||
| 118 | ), |
||
| 119 | 'externalReference' => null, |
||
| 120 | ], $customParams, $lineItem); |
||
| 121 | |||
| 122 | $this->positions[$this->ids->get($key)] = $position; |
||
| 123 | |||
| 124 | return $this; |
||
| 125 | } |
||
| 127 |