-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
src/Mapping/ClassMetadata.php
Outdated
*/ | ||
public function fullyQualifiedClassName(string|null $className): string|null | ||
{ | ||
if (empty($className)) { | ||
if ($className === null) { | ||
return $className; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/Mapping/ClassMetadata.php
Outdated
if ($repositoryClassName === null) { | ||
$this->customRepositoryClassName = null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot a return;
?
There was a problem hiding this comment.
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.
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.