magento2
magento2 copied to clipboard
[Issue] Fix PHPDocs for \Magento\Framework\Data\Collection::getItemById
trafficstars
This issue is automatically created based on existing pull request: magento/magento2#38439: Fix PHPDocs for \Magento\Framework\Data\Collection::getItemById
Add null as possible type returned by getItemById method.
Method returns null when item is not found.
PHPStan complains in the code using that method: Sample usage:
$product = $productCollection->getItemById(42);
if ($product) { # phpstan: If condition is always true.
// some logic
}
Result in PHPStorm:
Description (*)
Adds null type to PHPDocs of \Magento\Framework\Data\Collection::getItemById.
Fixes minor grammar issues in PHPDocs of that class.
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
- Create a module that uses any Collection and add code which reflects
ifcondition specified in the PR summary - Configure PHPStan with enabled
Treat PHPDoc types as certain(usually it is enabled by default) - Run static analysis (or open file in IDE with static analysis capabilities such as PHPStorm)
- There should be no warning/error
if condition is always true
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)