Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make phpdoc more precise for AbstractQuery #9777

Merged
merged 2 commits into from
May 24, 2022

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented May 22, 2022

Blocked by #9774

@greg0ire greg0ire force-pushed the improve-phpdoc-abstract-query branch 2 times, most recently from 15c0a1f to 52eb73a Compare May 23, 2022 19:33
@greg0ire greg0ire marked this pull request as ready for review May 23, 2022 19:37
* @param int $fetchMode
* @param class-string $class
* @param string $assocName
* @param ClassMetadata::FETCH_EAGER|ClassMetadata::FETCH_LAZY $fetchMode
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param ClassMetadata::FETCH_EAGER|ClassMetadata::FETCH_LAZY $fetchMode
* @param int $fetchMode
* @psalm-param ClassMetadata::FETCH_EAGER|ClassMetadata::FETCH_LAZY $fetchMode

I don't know how well literal types are supported outside of PHPStan and Psalm. So far, we have vendor-prefixed annotations that use them.

Copy link
Member

Choose a reason for hiding this comment

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

Looking at the implementation, it seems to hide potential errors. Invalid fetch modes are healed right now, but I think, we should deprecate them, so we can throw in 3.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, so let's keep int for now.

Copy link
Member

Choose a reason for hiding this comment

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

Documenting literal types is a good idea, I think. It's just that I would vendor-prefix the @param here.

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔 sounds like you would with with @VincentLanglet on #9778 then
In this particular instance, I think it can't hurt, and I would be eager to know what your stance is on that PR. I was wondering if we should:

  • only ever document the non-deprecated path
  • always document both
  • decide of that on a case-by-case basis.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it can't hurt

It already makes the build fail though, not sure that it's a great idea.

Copy link
Member

Choose a reason for hiding this comment

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

@param annotations should document the public API, the intended usage of that method. In this case: It is not intended that anyone would pass 42, 'hello world' or even an array or a cURL resource to this method although it has always been possible.

It already makes the build fail though

That's Psalm being Psalm. On 3.0, we would throw if the caller passed anything but the two allowed values, right? You would face the very same problem then. I'd argue that you cannot write that kind of input validation without Psalm complaining. PHPStan has a setting treatPhpDocTypesAsCertain for that very purpose.

@greg0ire greg0ire force-pushed the improve-phpdoc-abstract-query branch from 52eb73a to f1dfdf8 Compare May 23, 2022 20:47
@greg0ire greg0ire force-pushed the improve-phpdoc-abstract-query branch 2 times, most recently from 4d491c6 to a848d9d Compare May 23, 2022 20:51
lib/Doctrine/ORM/Query.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/Query.php Outdated Show resolved Hide resolved
@greg0ire greg0ire force-pushed the improve-phpdoc-abstract-query branch 2 times, most recently from d4f1ae5 to 691a021 Compare May 23, 2022 21:31
@greg0ire greg0ire closed this May 24, 2022
@greg0ire greg0ire reopened this May 24, 2022
@greg0ire greg0ire force-pushed the improve-phpdoc-abstract-query branch from 691a021 to 2aea57f Compare May 24, 2022 18:09
@greg0ire greg0ire requested a review from derrabus May 24, 2022 18:16
derrabus
derrabus previously approved these changes May 24, 2022
@greg0ire
Copy link
Member Author

Argh! a conflict!

@greg0ire greg0ire force-pushed the improve-phpdoc-abstract-query branch from 2aea57f to c1dd1cf Compare May 24, 2022 18:42
@greg0ire greg0ire enabled auto-merge May 24, 2022 18:42
@greg0ire greg0ire disabled auto-merge May 24, 2022 18:42
@greg0ire greg0ire merged commit 0f6f752 into doctrine:2.13.x May 24, 2022
@greg0ire greg0ire deleted the improve-phpdoc-abstract-query branch May 24, 2022 18:42
@derrabus derrabus mentioned this pull request May 30, 2022
@greg0ire greg0ire mentioned this pull request Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants