-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
fix AttributeReader:getPropertyAnnotation AttributeReader:getMethodAnnotation #1404
base: master
Are you sure you want to change the base?
Conversation
Hello @andriinavrotskii ! Thank you for your PR! Could you tell a bit more about the issue that is solves? Is it possible to add some unit tests that was not working before this changes? Best, Marcin. |
Hi, Marcin. Problem:
Method Doctrine\Common\Annotations\Reader::getClassAnnotation(ReflectionClass $class, $annotationName) has attribute "$class" typehinted as ReflectionClass Method JMS\Serializer\Metadata\Driver\AttributeDriver\AttributeReader::getPropertyAnnotation(ReflectionProperty $property, $annotationName) got "$property" typehinted as ReflectionProperty Same for getMethodAnnotation - we try to send instance of ReflectionMethod to method getClassAnnotation which expect instance of ReflectionClass |
is there a way to provide a test case for this? |
Looking closer at the AttributeReader class it seems the I think the solution from this commit is not correct because when you call IMO the fix is to call to the delegated reader with the same method names. public function getMethodAnnotation(ReflectionMethod $method, $annotationName): ?object
{
$attributes = $method->getAttributes($annotationName);
return $this->reader->getMethodAnnotation($method, $annotationName) ?? $this->buildAnnotation($attributes);
}
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName): ?object
{
$attributes = $property->getAttributes($annotationName);
return $this->reader->getPropertyAnnotation($property, $annotationName) ?? $this->buildAnnotation($attributes);
} |
return $this->reader->getClassAnnotation(new ReflectionClass($method->class), $annotationName) | ||
?? $this->buildAnnotation($attributes); |
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.
return $this->reader->getClassAnnotation(new ReflectionClass($method->class), $annotationName) | |
?? $this->buildAnnotation($attributes); | |
return $this->reader->getMethodAnnotation($method, $annotationName) ?? $this->buildAnnotation($attributes); |
return $this->reader->getClassAnnotation(new ReflectionClass($property->class), $annotationName) | ||
?? $this->buildAnnotation($attributes); |
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.
return $this->reader->getClassAnnotation(new ReflectionClass($property->class), $annotationName) | |
?? $this->buildAnnotation($attributes); | |
return $this->reader->getPropertyAnnotation($property, $annotationName) ?? $this->buildAnnotation($attributes); |
@mbabker you have worked on this area...would you mind having a look at this? |
| Bug fix? | yes