-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
This issue is automatically created based on existing pull request: #39389: Fix incorrect return type for getOptionByCode method
Description (*)
I've noticed that \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface::getOptionByCode
return type is defined as object all the time:
magento2/app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemInterface.php
Lines 24 to 30 in b2ce2a3
/** | |
* Get item option by code | |
* | |
* @param string $code | |
* @return \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface | |
*/ | |
public function getOptionByCode($code); |
However, this interface implements 3 classes, and each of them returns object OR null, so it's a bug in the method definition on interface:
magento2/app/code/Magento/Quote/Model/Quote/Address/Item.php
Lines 200 to 210 in 6729b6e
/** * @inheritdoc * @since 101.1.1 */ public function getOptionByCode($code) { if ($this->getQuoteItem()) { return $this->getQuoteItem()->getOptionBycode($code); } return null; } magento2/app/code/Magento/Quote/Model/Quote/Item.php
Lines 726 to 738 in 2afe92f
/** * Get item option by code * * @param string $code * @return \Magento\Quote\Model\Quote\Item\Option || null */ public function getOptionByCode($code) { if (isset($this->_optionsByCode[$code]) && !$this->_optionsByCode[$code]->isDeleted()) { return $this->_optionsByCode[$code]; } return null; } magento2/app/code/Magento/Wishlist/Model/Item.php
Lines 697 to 709 in 795b2c6
/** * Get item option by code * * @param string $code * @return Option|null */ public function getOptionByCode($code) { if (isset($this->_optionsByCode[$code]) && !$this->_optionsByCode[$code]->isDeleted()) { return $this->_optionsByCode[$code]; } return null; }
This pull request fixes incorrect phpdoc block, which leads to confusion, which leads to bugs during development
Related Pull Requests
Fixed Issues (if relevant)
- Fixes magento/magento2#<issue_number>
Manual testing scenarios (*)
- ...
- ...
Questions or comments
Contribution checklist (*)
- Pull request has a meaningful description of its purpose
- All commits are accompanied by meaningful commit messages
- All new or changed code is covered with unit/integration tests (if applicable)
- README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- All automated tests passed successfully (all builds are green)