Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit ab90b21

Browse files
committed
Improve constructor arguments, arguments by reference is not valid and change SuppressWarnings
1 parent 900b05f commit ab90b21

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
use Magento\Framework\View\Result\LayoutFactory;
2525
use Magento\Framework\Controller\Result\RawFactory;
2626
use Magento\Framework\Exception\LocalizedException;
27+
use Magento\Framework\App\ObjectManager;
2728

2829
/**
2930
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3131
*/
3232
class AddressSave extends Order
3333
{
@@ -55,8 +55,9 @@ class AddressSave extends Order
5555
* @param OrderManagementInterface $orderManagement
5656
* @param OrderRepositoryInterface $orderRepository
5757
* @param LoggerInterface $logger
58-
* @param RegionFactory $regionFactory
58+
* @param RegionFactory|null $regionFactory
5959
*
60+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6061
*/
6162
public function __construct(
6263
Context $context,
@@ -70,9 +71,9 @@ public function __construct(
7071
OrderManagementInterface $orderManagement,
7172
OrderRepositoryInterface $orderRepository,
7273
LoggerInterface $logger,
73-
RegionFactory $regionFactory
74+
RegionFactory $regionFactory = null
7475
) {
75-
$this->regionFactory = $regionFactory;
76+
$this->regionFactory = $regionFactory ?: ObjectManager::getInstance()->get(RegionFactory::class);
7677
parent::__construct(
7778
$context,
7879
$coreRegistry,
@@ -101,7 +102,7 @@ public function execute()
101102
OrderAddressInterface::class
102103
)->load($addressId);
103104
$data = $this->getRequest()->getPostValue();
104-
$this->updateRegionData($data);
105+
$data = $this->updateRegionData($data);
105106
$resultRedirect = $this->resultRedirectFactory->create();
106107
if ($data && $address->getId()) {
107108
$address->addData($data);
@@ -130,14 +131,15 @@ public function execute()
130131
* Update region data
131132
*
132133
* @param array $attributeValues
133-
* @return void
134+
* @return array
134135
*/
135-
protected function updateRegionData(&$attributeValues)
136+
protected function updateRegionData($attributeValues)
136137
{
137138
if (!empty($attributeValues['region_id'])) {
138139
$newRegion = $this->regionFactory->create()->load($attributeValues['region_id']);
139140
$attributeValues['region_code'] = $newRegion->getCode();
140141
$attributeValues['region'] = $newRegion->getDefaultName();
141142
}
143+
return $attributeValues;
142144
}
143145
}

0 commit comments

Comments
 (0)