| Conditions | 9 |
| Paths | 54 |
| Total Lines | 56 |
| Code Lines | 36 |
| 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 |
||
| 83 | private function instantiateOrderItems(array $items = array()) |
||
| 84 | { |
||
| 85 | try { |
||
| 86 | $order = new Order(); |
||
| 87 | $order->setCurrency($this->context->getCurrency()); |
||
| 88 | $order->setUser($this->subscriptionService->getCurrentUser()); |
||
| 89 | foreach ($items as $subscriptionId => $periodId) { |
||
| 90 | if (!$periodId) { |
||
| 91 | continue; |
||
| 92 | } |
||
| 93 | |||
| 94 | $orderItem = null; |
||
| 95 | $subscription = $this->subscriptionService |
||
| 96 | ->getSubscriptionRepository() |
||
| 97 | ->getReference($subscriptionId); |
||
| 98 | |||
| 99 | $newlySelectedPeriod = $this->subscriptionService->filterRanges($subscription, $periodId); |
||
| 100 | if (!$newlySelectedPeriod) { |
||
| 101 | return new Order(); |
||
| 102 | } |
||
| 103 | |||
| 104 | $item = $this->subscriptionService->getOrderItemBy( |
||
| 105 | $subscription->getId() |
||
| 106 | ); |
||
| 107 | |||
| 108 | if ($item) { |
||
| 109 | if (!$item->isActive()) { |
||
| 110 | continue; |
||
| 111 | } |
||
| 112 | |||
| 113 | $currentItemPeriod = $item->getDuration(); |
||
| 114 | // e.g month === month |
||
| 115 | if ($currentItemPeriod['attribute'] === $newlySelectedPeriod->getAttribute()) { |
||
| 116 | $orderItem = $this->instantiateOrderItem($subscription, $newlySelectedPeriod); |
||
| 117 | $orderItem->setProlonged(true); |
||
| 118 | $orderItem->setParent($item); |
||
| 119 | $orderItem->setCreatedAt($item->getCreatedAt()); |
||
| 120 | $orderItem->setStartsAt($item->getExpireAt()); |
||
| 121 | } else { |
||
| 122 | continue; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | if (!$orderItem) { |
||
| 127 | $orderItem = $this->instantiateOrderItem($subscription, $newlySelectedPeriod); |
||
| 128 | } |
||
| 129 | |||
| 130 | $orderItem->setOrder($order); |
||
| 131 | $order->addItem($orderItem); |
||
| 132 | } |
||
| 133 | |||
| 134 | return $order; |
||
| 135 | } catch (\Exception $e) { |
||
| 136 | throw $e; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 192 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.