Skip to content

Commit 34819da

Browse files
author
Oleksii Korshenko
committed
MAGETWO-70020: Improved type hints and declarations for \Magento\Quote\Model\Quote\Address\Total #9986
- Merge Pull Request #9986 from schmengler/magento2:quote-total-type - Merged commits: 1. fb3b977 2. 160327b 3. f7aea83 4. 99a4d69
2 parents d6efc8e + 99a4d69 commit 34819da

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ public function collectTotals()
19441944
/**
19451945
* Get all quote totals (sorted by priority)
19461946
*
1947-
* @return array
1947+
* @return Address\Total[]
19481948
*/
19491949
public function getTotals()
19501950
{

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
namespace Magento\Quote\Model\Quote\Address;
77

88
/**
9+
* @method string getCode()
10+
*
911
* @api
1012
*/
1113
class Total extends \Magento\Framework\DataObject
1214
{
1315
/**
1416
* @var array
1517
*/
16-
protected $totalAmounts;
18+
protected $totalAmounts = [];
1719

1820
/**
1921
* @var array
2022
*/
21-
protected $baseTotalAmounts;
23+
protected $baseTotalAmounts = [];
2224

2325
/**
2426
* Serializer interface instance.

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: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ public function __construct(
3535
/**
3636
* @param \Magento\Quote\Model\Quote $quote
3737
* @param array $total
38-
* @return array
38+
* @return Total[]
3939
*/
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);
@@ -62,7 +62,7 @@ public function fetch(\Magento\Quote\Model\Quote $quote, array $total)
6262

6363
/**
6464
* @param array $total
65-
* @return Total|array
65+
* @return Total|Total[]
6666
*/
6767
protected function convert($total)
6868
{
@@ -73,22 +73,20 @@ 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
/**
8785
* @param Total $totalInstance
88-
* @param array $output
89-
* @return array
86+
* @param Total[] $output
87+
* @return Total[]
9088
*/
91-
protected function merge($totalInstance, $output)
89+
protected function merge(Total $totalInstance, $output)
9290
{
9391
if (array_key_exists($totalInstance->getCode(), $output)) {
9492
$output[$totalInstance->getCode()] = $output[$totalInstance->getCode()]->addData(

0 commit comments

Comments
 (0)