Skip to content

Conversation

MTheProgrammer
Copy link
Contributor

@MTheProgrammer MTheProgrammer commented Feb 13, 2024

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)

Resolved issues:

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

Copy link

m2-assistant bot commented Feb 13, 2024

Hi @MTheProgrammer. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.

Add the comment under your pull request to deploy test or vanilla Magento instance:
  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@MTheProgrammer
Copy link
Contributor Author

@magento give me test instance

Copy link

Hi @MTheProgrammer. Thank you for your request. I'm working on Magento instance for you.

Copy link

@MTheProgrammer
Copy link
Contributor Author

@magento run all tests

@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Feb 13, 2024
@edenduong edenduong assigned edenduong and unassigned edenduong Feb 23, 2024
@edenduong edenduong self-requested a review February 23, 2024 04:45
Copy link
Contributor

@edenduong edenduong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@engcom-Delta
Copy link
Contributor

@magento create issue

@engcom-Delta engcom-Delta added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Feb 29, 2024
@andrewbess
Copy link
Contributor

@magento run all tests

@sinhaparul sinhaparul added the Project: Community Picked PRs upvoted by the community label Mar 4, 2024
@MTheProgrammer
Copy link
Contributor Author

It fails Semantic Version Checker test because of the fix in PHPDocs, but no API is changed in reality. Code is the same. How to deal with this?

Suggested version increase (based on PHP code analysis and files changed) MAJOR

@engcom-Echo
Copy link
Contributor

@magento run all tests

@engcom-November
Copy link
Contributor

engcom-November commented Mar 7, 2024

✔️ QA Passed

Manual testing scenario:

  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

Before: ❌
image
Warning stating that if condition is always true.

After: ✔️
Screenshot 2024-03-07 at 1 42 54 PM
There is no warning/error that if condition is always true.

Since the tests are failing, moving this to Extended Testing.

@engcom-November
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests EE, Semantic Version Checker

@engcom-November
Copy link
Contributor

@magento run all tests

@engcom-November
Copy link
Contributor

@magento run all tests

@engcom-November
Copy link
Contributor

engcom-November commented Mar 13, 2024

As SVC tests are failing we have raised a internal approval jira AC-11580, hence moving this to Pending Approval.

@engcom-November
Copy link
Contributor

Since we got the approval for SVC failure AC-11580, moving this to extended testing because of failed builds.

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-November
Copy link
Contributor

@magento run Functional Tests CE, Functional Tests EE, Functional Tests B2B, Integration Tests, WebAPI Tests

@engcom-November
Copy link
Contributor

@magento run Functional Tests EE

@engcom-November
Copy link
Contributor

Functional Tests CE, Functional Tests EE and Functional Tests B2B are different on last two runs on same commit.

Functional Tests CE :
Contains know failures:
ACQE-6102
Run 1 :
image

Run 2 :
image

Functional Tests EE :
Contains know failures:
ACQE-6331
Run 1 :
image

Run 2 :
image

Functional Tests B2B :
Contains know failures:
ACQE-6363
Run 1 :
image

Run 2 :
image

@engcom-November
Copy link
Contributor

WebAPI Tests :
GRAPHQL WebAPI tests for CE :
Run 1 :
image

Run 2 :
image

Executed the same test locally but the error was not reproducible.
So this seems to be flaky.

Hence moving this to Merge in Progress.

@magento-devops-reposync-svc magento-devops-reposync-svc merged commit f439b52 into magento:2.4-develop May 16, 2024
@MTheProgrammer MTheProgrammer deleted the bugfix/data-collection-typehint branch May 29, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept Project: Community Picked PRs upvoted by the community Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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