Skip to content

Commit 160327b

Browse files
committed
Add default behavior to Quote\Address\TotalFactory
The factory is used like a default generated factory in TotalsReader but needed to pass the class name to create(). This violates the POLA. Also, the return type hint is adjusted now (Total is no subtype of Total\AbstractTotal)
1 parent fb3b977 commit 160327b

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

app/code/Magento/Quote/Model/Quote/Address/TotalFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objManage
3333
*
3434
* @param string $instanceName
3535
* @param array $data
36-
* @return \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
36+
* @return Total\AbstractTotal|Total
3737
*/
38-
public function create($instanceName, array $data = [])
38+
public function create($instanceName = Total::class, array $data = [])
3939
{
4040
return $this->_objectManager->create($instanceName, $data);
4141
}

app/code/Magento/Quote/Model/Quote/TotalsReader.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(
4040
public function fetch(\Magento\Quote\Model\Quote $quote, array $total)
4141
{
4242
$output = [];
43-
$total = $this->totalFactory->create(\Magento\Quote\Model\Quote\Address\Total::class)->setData($total);
43+
$total = $this->totalFactory->create()->setData($total);
4444
/** @var ReaderInterface $reader */
4545
foreach ($this->collectorList->getCollectors($quote->getStoreId()) as $reader) {
4646
$data = $reader->fetch($quote, $total);
@@ -73,14 +73,12 @@ protected function convert($total)
7373
if (count(array_column($total, 'code')) > 0) {
7474
$totals = [];
7575
foreach ($total as $item) {
76-
$totals[] = $this->totalFactory->create(
77-
\Magento\Quote\Model\Quote\Address\Total::class
78-
)->setData($item);
76+
$totals[] = $this->totalFactory->create()->setData($item);
7977
}
8078
return $totals;
8179
}
8280

83-
return $this->totalFactory->create(\Magento\Quote\Model\Quote\Address\Total::class)->setData($total);
81+
return $this->totalFactory->create()->setData($total);
8482
}
8583

8684
/**

0 commit comments

Comments
 (0)