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

Developer Experience: Quote AbstractItem code style (SwiftOtter's SOP-348) #39331

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
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
62 changes: 26 additions & 36 deletions app/code/Magento/Quote/Model/Quote/Item/AbstractItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Quote\Model\Quote\Item;

use Magento\Quote\Model\Quote\Item;
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Quote\Model\Quote\Item;

/**
* Quote item abstract model
Expand All @@ -24,15 +26,15 @@
* @method float getBaseDiscountAmount()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setBaseDiscountAmount(float $amount)
* @method float getDiscountPercent()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setDiscountPercent()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setDiscountPercent(float $percent)
* @method float getOriginalDiscountAmount()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setOriginalDiscountAmount()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setOriginalDiscountAmount(float $amount)
* @method float getBaseOriginalDiscountAmount()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setBaseOriginalDiscountAmount()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setBaseOriginalDiscountAmount(float $amount)
* @method float getDiscountCalculationPrice()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setDiscountCalculationPrice()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setDiscountCalculationPrice(float $amount)
* @method float getBaseDiscountCalculationPrice()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setBaseDiscountCalculationPrice($price)
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setBaseDiscountCalculationPrice(float $price)
* @method int[] getAppliedRuleIds()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setAppliedRuleIds(array $ruleIds)
* @method float getBaseTaxAmount()
Expand All @@ -47,8 +49,8 @@
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @since 100.0.2
*/
abstract class AbstractItem extends \Magento\Framework\Model\AbstractExtensibleModel implements
\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface
abstract class AbstractItem extends \Magento\Framework\Model\AbstractExtensibleModel
implements \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface
{
/**
* @var Item|null
Expand All @@ -68,7 +70,7 @@ abstract class AbstractItem extends \Magento\Framework\Model\AbstractExtensibleM
/**
* List of custom options
*
* @var array
* @var OptionInterface[]
*/
protected $_optionsByCode;

Expand Down Expand Up @@ -187,7 +189,7 @@ public function beforeSave()
/**
* Set parent item
*
* @param Item $parentItem
* @param Item $parentItem
* @return $this
*/
public function setParentItem($parentItem)
Expand Down Expand Up @@ -222,7 +224,7 @@ public function getChildren()
/**
* Add child item
*
* @param \Magento\Quote\Model\Quote\Item\AbstractItem $child
* @param \Magento\Quote\Model\Quote\Item\AbstractItem $child
* @return $this
*/
public function addChild($child)
Expand All @@ -235,7 +237,7 @@ public function addChild($child)
/**
* Adds message(s) for quote item. Duplicated messages are not added.
*
* @param mixed $messages
* @param mixed $messages
* @return $this
*/
public function setMessage($messages)
Expand All @@ -255,7 +257,7 @@ public function setMessage($messages)
/**
* Add message of quote item to array of messages
*
* @param string $message
* @param string $message
* @return $this
*/
public function addMessage($message)
Expand All @@ -267,7 +269,7 @@ public function addMessage($message)
/**
* Get messages array of quote item
*
* @param bool $string flag for converting messages to string
* @param bool $string flag for converting messages to string
* @return array|string
*/
public function getMessage($string = true)
Expand Down Expand Up @@ -624,18 +626,12 @@ public function __clone()
*/
public function isChildrenCalculated()
{
if ($this->getParentItem()) {
$calculate = $this->getParentItem()->getProduct()->getPriceType();
} else {
$calculate = $this->getProduct()->getPriceType();
}
$calculate = $this->getParentItem()
? $this->getParentItem()->getProduct()->getPriceType()
: $this->getProduct()->getPriceType();

if (null !== $calculate &&
(int)$calculate === \Magento\Catalog\Model\Product\Type\AbstractType::CALCULATE_CHILD
) {
return true;
}
return false;
return $calculate !== null
&& (int)$calculate === \Magento\Catalog\Model\Product\Type\AbstractType::CALCULATE_CHILD;
}

/**
Expand All @@ -648,18 +644,12 @@ public function isChildrenCalculated()
*/
public function isShipSeparately()
{
if ($this->getParentItem()) {
$shipmentType = $this->getParentItem()->getProduct()->getShipmentType();
} else {
$shipmentType = $this->getProduct()->getShipmentType();
}
$shipmentType = $this->getParentItem()
? $this->getParentItem()->getProduct()->getShipmentType()
: $this->getProduct()->getShipmentType();

if (null !== $shipmentType &&
(int)$shipmentType === \Magento\Catalog\Model\Product\Type\AbstractType::SHIPMENT_SEPARATELY
) {
return true;
}
return false;
return null !== $shipmentType &&
(int)$shipmentType === \Magento\Catalog\Model\Product\Type\AbstractType::SHIPMENT_SEPARATELY;
}

/**
Expand Down