Skip to content

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

@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #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)

Metadata

Metadata

Labels

Area: FrameworkComponent: StaticTestIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions