Conditions | 5 |
Paths | 3 |
Total Lines | 54 |
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 |
||
85 | public function parseResults(LoopResult $loopResult) |
||
86 | { |
||
87 | $taxCountry = $this->container->get('thelia.taxEngine')->getDeliveryCountry(); |
||
88 | $locale = $this->getCurrentRequest()->getSession()->getLang()->getLocale(); |
||
89 | $checkAvailability = ConfigQuery::checkAvailableStock(); |
||
90 | $defaultAvailability = \intval(ConfigQuery::read('default-available-stock', 100)); |
||
91 | |||
92 | /** @var CartItemModel $cartItem */ |
||
93 | foreach ($loopResult->getResultDataCollection() as $cartItem) { |
||
94 | $product = $cartItem->getProduct(null, $locale); |
||
95 | $productSaleElement = $cartItem->getProductSaleElements(); |
||
96 | |||
97 | $loopResultRow = new LoopResultRow($cartItem); |
||
98 | |||
99 | $loopResultRow->set("ITEM_ID", $cartItem->getId()); |
||
100 | $loopResultRow->set("TITLE", $product->getTitle()); |
||
101 | $loopResultRow->set("REF", $product->getRef()); |
||
102 | $loopResultRow->set("QUANTITY", $cartItem->getQuantity()); |
||
103 | $loopResultRow->set("PRODUCT_ID", $product->getId()); |
||
104 | $loopResultRow->set("PRODUCT_URL", $product->getUrl($this->getCurrentRequest()->getSession()->getLang()->getLocale())); |
||
105 | if (!$checkAvailability || $product->getVirtual() === 1) { |
||
106 | $loopResultRow->set("STOCK", $defaultAvailability); |
||
107 | } else { |
||
108 | $loopResultRow->set("STOCK", $productSaleElement->getQuantity()); |
||
109 | } |
||
110 | $loopResultRow |
||
111 | ->set("PRICE", $cartItem->getPrice()) |
||
112 | ->set("PROMO_PRICE", $cartItem->getPromoPrice()) |
||
113 | ->set("TAXED_PRICE", $cartItem->getTaxedPrice($taxCountry)) |
||
114 | ->set("PROMO_TAXED_PRICE", $cartItem->getTaxedPromoPrice($taxCountry)) |
||
115 | ->set("IS_PROMO", $cartItem->getPromo() === 1 ? 1 : 0) |
||
116 | ; |
||
117 | |||
118 | $loopResultRow |
||
119 | ->set("TOTAL_PRICE", $cartItem->getTotalPrice()) |
||
120 | ->set("TOTAL_PROMO_PRICE", $cartItem->getTotalPromoPrice()) |
||
121 | ->set("TOTAL_TAXED_PRICE", $cartItem->getTotalTaxedPrice($taxCountry)) |
||
122 | ->set("TOTAL_PROMO_TAXED_PRICE", $cartItem->getTotalTaxedPromoPrice($taxCountry)) |
||
123 | ; |
||
124 | |||
125 | $loopResultRow |
||
126 | ->set("REAL_PRICE", $cartItem->getRealPrice()) |
||
127 | ->set("REAL_TAXED_PRICE", $cartItem->getRealTaxedPrice($taxCountry)) |
||
128 | ->set("REAL_TOTAL_PRICE", $cartItem->getTotalRealPrice($taxCountry)) |
||
129 | ->set("REAL_TOTAL_TAXED_PRICE", $cartItem->getTotalRealTaxedPrice($taxCountry)) |
||
130 | ; |
||
131 | |||
132 | $loopResultRow->set("PRODUCT_SALE_ELEMENTS_ID", $productSaleElement->getId()); |
||
133 | $loopResultRow->set("PRODUCT_SALE_ELEMENTS_REF", $productSaleElement->getRef()); |
||
134 | $this->addOutputFields($loopResultRow, $cartItem); |
||
135 | $loopResult->addRow($loopResultRow); |
||
136 | } |
||
137 | |||
138 | return $loopResult; |
||
139 | } |
||
151 |