diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 12444c9cce202..a9907c1661bd8 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -10,6 +10,7 @@ use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Api\ProductLinkRepositoryInterface; use Magento\Catalog\Model\Product\Attribute\Backend\Media\EntryConverterPool; +use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface; use Magento\Catalog\Model\FilterProductCustomAttribute; use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\App\Filesystem\DirectoryList; @@ -108,7 +109,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements /** * Product object customization (not stored in DB) * - * @var array + * @var OptionInterface[] */ protected $_customOptions = []; @@ -2062,7 +2063,7 @@ public function addCustomOption($code, $value, $product = null) /** * Sets custom options for the product * - * @param array $options Array of options + * @param OptionInterface[] $options Array of options * @return void */ public function setCustomOptions(array $options) @@ -2073,7 +2074,7 @@ public function setCustomOptions(array $options) /** * Get all custom options of the product * - * @return array + * @return OptionInterface[] */ public function getCustomOptions() { @@ -2084,14 +2085,11 @@ public function getCustomOptions() * Get product custom option info * * @param string $code - * @return array + * @return OptionInterface|null */ public function getCustomOption($code) { - if (isset($this->_customOptions[$code])) { - return $this->_customOptions[$code]; - } - return null; + return $this->_customOptions[$code] ?? null; } /** @@ -2101,11 +2099,7 @@ public function getCustomOption($code) */ public function hasCustomOptions() { - if (count($this->_customOptions)) { - return true; - } else { - return false; - } + return (bool)count($this->_customOptions); } /** @@ -2405,16 +2399,14 @@ public function reloadPriceInfo() } } - // phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames /** * Return Data Object data in array format. * * @return array * @todo refactor with converter for AbstractExtensibleModel */ - public function __toArray() + public function __toArray() //phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames { - // phpcs:enable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames $data = $this->_data; $hasToArray = function ($model) { return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']);