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

Translate comment into code and annotations #11294

Merged
merged 2 commits into from Feb 25, 2024
Merged

Conversation

greg0ire
Copy link
Member

The phpdoc comment for the return type of
ClassMetadata::fullyQualifiedClassName() says that the return type will be null if the input value is null. I have made it more precise by using "if and only if", made the null check more strict and translated that into template annotations. Also, since we say we return a class-string, I've asserted that.

*/
public function fullyQualifiedClassName(string|null $className): string|null
{
if (empty($className)) {
if ($className === null) {
return $className;
Copy link
Member

Choose a reason for hiding this comment

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

Let's do return null; instead?

* @return string|null null if and only if the input value is null
* @psalm-return (C is string ? string : null)
*
* @template C of string|null
*/
public function fullyQualifiedClassName(string|null $className): string|null
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to call this method with null? Should we rather deprecate that case?

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 would. Right now, it is only useful for a call from setCustomRepositoryClass. Let me push an extra commit that adds the deprecation.

The phpdoc comment for the return type of
ClassMetadata::fullyQualifiedClassName() says that the return type will
be null if the input value is null. I have made it more precise by
using "if and only if", made the null check more strict and translated
that into template annotations. Also, since we say we return a
class-string, I've asserted that.
Comment on lines 2007 to 2011
if ($repositoryClassName === null) {
$this->customRepositoryClassName = null;
}
Copy link
Member

Choose a reason for hiding this comment

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

Forgot a return;?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, that's me 🤦

It can easily be avoided by the only caller.
@greg0ire greg0ire added this to the 3.1.0 milestone Feb 25, 2024
@greg0ire greg0ire merged commit ee5b2ce into doctrine:3.1.x Feb 25, 2024
64 checks passed
@greg0ire greg0ire deleted the sa-fqcn branch February 25, 2024 09:01
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.

None yet

2 participants