Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved type hints and declarations for \Magento\Quote\Model\Quote\Address\Total #9986

Merged
merged 4 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/code/Magento/Quote/Model/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ public function collectTotals()
/**
* Get all quote totals (sorted by priority)
*
* @return array
* @return Address\Total[]
*/
public function getTotals()
{
Expand Down
6 changes: 4 additions & 2 deletions app/code/Magento/Quote/Model/Quote/Address/Total.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
namespace Magento\Quote\Model\Quote\Address;

/**
* @method string getCode()
*
* @api
*/
class Total extends \Magento\Framework\DataObject
{
/**
* @var array
*/
protected $totalAmounts;
protected $totalAmounts = [];

/**
* @var array
*/
protected $baseTotalAmounts;
protected $baseTotalAmounts = [];

/**
* Serializer interface instance.
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Quote/Model/Quote/Address/TotalFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objManage
*
* @param string $instanceName
* @param array $data
* @return \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
* @return Total\AbstractTotal|Total
*/
public function create($instanceName, array $data = [])
public function create($instanceName = Total::class, array $data = [])
{
return $this->_objectManager->create($instanceName, $data);
}
Expand Down
18 changes: 8 additions & 10 deletions app/code/Magento/Quote/Model/Quote/TotalsReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public function __construct(
/**
* @param \Magento\Quote\Model\Quote $quote
* @param array $total
* @return array
* @return Total[]
*/
public function fetch(\Magento\Quote\Model\Quote $quote, array $total)
{
$output = [];
$total = $this->totalFactory->create(\Magento\Quote\Model\Quote\Address\Total::class)->setData($total);
$total = $this->totalFactory->create()->setData($total);
/** @var ReaderInterface $reader */
foreach ($this->collectorList->getCollectors($quote->getStoreId()) as $reader) {
$data = $reader->fetch($quote, $total);
Expand All @@ -62,7 +62,7 @@ public function fetch(\Magento\Quote\Model\Quote $quote, array $total)

/**
* @param array $total
* @return Total|array
* @return Total|Total[]
*/
protected function convert($total)
{
Expand All @@ -73,22 +73,20 @@ protected function convert($total)
if (count(array_column($total, 'code')) > 0) {
$totals = [];
foreach ($total as $item) {
$totals[] = $this->totalFactory->create(
\Magento\Quote\Model\Quote\Address\Total::class
)->setData($item);
$totals[] = $this->totalFactory->create()->setData($item);
}
return $totals;
}

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

/**
* @param Total $totalInstance
* @param array $output
* @return array
* @param Total[] $output
* @return Total[]
*/
protected function merge($totalInstance, $output)
protected function merge(Total $totalInstance, $output)
{
if (array_key_exists($totalInstance->getCode(), $output)) {
$output[$totalInstance->getCode()] = $output[$totalInstance->getCode()]->addData(
Expand Down