Skip to content

Commit d2a09d3

Browse files
committed
testCodeStyle
1 parent 0a67f76 commit d2a09d3

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

app/code/Magento/Checkout/Controller/Cart/UpdateItemQty.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
use Magento\Checkout\Model\Cart\RequestQuantityProcessor;
1111
use Magento\Checkout\Model\Session as CheckoutSession;
12+
use Magento\Framework\App\Action\Action;
1213
use Magento\Framework\App\Action\Context;
14+
use Magento\Framework\App\Action\HttpPostActionInterface;
1315
use Magento\Framework\Data\Form\FormKey\Validator as FormKeyValidator;
1416
use Magento\Framework\Exception\LocalizedException;
1517
use Magento\Framework\Exception\NotFoundException;
1618
use Magento\Framework\Serialize\Serializer\Json;
1719
use Magento\Quote\Model\Quote\Item;
18-
use Magento\Framework\App\Action\Action;
19-
use Magento\Framework\App\Action\HttpPostActionInterface;
2020
use Psr\Log\LoggerInterface;
2121

2222
/**
@@ -26,6 +26,7 @@
2626
*/
2727
class UpdateItemQty extends Action implements HttpPostActionInterface
2828
{
29+
2930
/**
3031
* @var RequestQuantityProcessor
3132
*/
@@ -76,9 +77,7 @@ public function __construct(
7677
$this->json = $json;
7778
$this->logger = $logger;
7879
parent::__construct($context);
79-
80-
}
81-
80+
}//end __construct()
8281

8382
/**
8483
* Controller execute method
@@ -96,11 +95,11 @@ public function execute()
9695
$this->validateCartData($cartData);
9796

9897
$cartData = $this->quantityProcessor->process($cartData);
99-
$quote = $this->checkoutSession->getQuote();
98+
$quote = $this->checkoutSession->getQuote();
10099

101100
foreach ($cartData as $itemId => $itemInfo) {
102101
$item = $quote->getItemById($itemId);
103-
$qty = isset($itemInfo['qty']) ? (double)$itemInfo['qty'] : 0;
102+
$qty = isset($itemInfo['qty']) ? (double) $itemInfo['qty'] : 0;
104103
if ($item) {
105104
$this->updateItemQuantity($item, $qty);
106105
}
@@ -112,8 +111,8 @@ public function execute()
112111
} catch (\Exception $e) {
113112
$this->logger->critical($e->getMessage());
114113
$this->jsonResponse('Something went wrong while saving the page. Please refresh the page and try again.');
115-
}
116-
}
114+
}//end try
115+
}//end execute()
117116

118117
/**
119118
* Updates quote item quantity.
@@ -135,7 +134,7 @@ private function updateItemQuantity(Item $item, float $qty)
135134
throw new LocalizedException(__($item->getMessage()));
136135
}
137136
}
138-
}
137+
}//end updateItemQuantity()
139138

140139
/**
141140
* JSON response builder.
@@ -149,7 +148,7 @@ private function jsonResponse(string $error = '')
149148
$this->getResponse()->representJson(
150149
$this->json->serialize($this->getResponseData($error))
151150
);
152-
}
151+
}//end jsonResponse()
153152

154153
/**
155154
* Returns response data.
@@ -160,19 +159,17 @@ private function jsonResponse(string $error = '')
160159
*/
161160
private function getResponseData(string $error = ''): array
162161
{
163-
$response = [
164-
'success' => true,
165-
];
162+
$response = ['success' => true];
166163

167164
if (!empty($error)) {
168165
$response = [
169-
'success' => false,
166+
'success' => false,
170167
'error_message' => $error,
171168
];
172169
}
173170

174171
return $response;
175-
}
172+
}//end getResponseData()
176173

177174
/**
178175
* Validates the Request HTTP method
@@ -184,12 +181,9 @@ private function getResponseData(string $error = ''): array
184181
private function validateRequest()
185182
{
186183
if ($this->getRequest()->isPost() === false) {
187-
throw new NotFoundException(
188-
__('Page Not Found')
189-
);
184+
throw new NotFoundException(__('Page Not Found'));
190185
}
191-
192-
}
186+
}//end validateRequest()
193187

194188
/**
195189
* Validates form key
@@ -205,8 +199,7 @@ private function validateFormKey()
205199
__('Something went wrong while saving the page. Please refresh the page and try again.')
206200
);
207201
}
208-
209-
}
202+
}//end validateFormKey()
210203

211204
/**
212205
* Validates cart data
@@ -224,6 +217,5 @@ private function validateCartData($cartData = null)
224217
__('Something went wrong while saving the page. Please refresh the page and try again.')
225218
);
226219
}
227-
228-
}
229-
}
220+
}//end validateCartData()
221+
}//end class

0 commit comments

Comments
 (0)