magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

[Issue] Fix PHPDocs for \Magento\Framework\Data\Collection::getItemById

Open m2-assistant[bot] opened this issue 1 year ago • 0 comments
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: image

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 (*)

  1. Create a module that uses any Collection and add code which reflects if condition specified in the PR summary
  2. Configure PHPStan with enabled Treat PHPDoc types as certain (usually it is enabled by default)
  3. Run static analysis (or open file in IDE with static analysis capabilities such as PHPStorm)
  4. 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)

m2-assistant[bot] avatar Feb 29 '24 13:02 m2-assistant[bot]