-
Notifications
You must be signed in to change notification settings - Fork 235
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
PhpParser does not parse use statements from traits. #20
Conversation
this adds a failing test for this issue.
phpparser returns aliased namespace different. now it tests both.
@@ -57,6 +57,12 @@ public function parseClass(\ReflectionClass $class) | |||
|
|||
$statements = $tokenizer->parseUseStatements($class->getNamespaceName()); | |||
|
|||
if (method_exists($class, 'getTraits') && $traits = $class->getTraits()) { | |||
foreach($traits as $trait) { |
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.
Alignment and PSR-2 compliance
Looks good 👍 |
this looks wrong to me: use statements of traits should only affect annotations set on properties and methods coming from the trait, not the whole class |
This would make sense, if ReflectionClass::getMethods() would make a difference on the origin of a method. |
@jaypea If you have 2 annotation classes with the same short class name but in different namespaces, using one of them in the trait and the other one in the class itself will break in case you combine use statements. |
Yes, the behaviour is atleast undefined, it would use whichever of possible the Annotation classes. btw: (ReflectionMethod->getFilename() !== ReflectionMethod->getDeclaringClass()->getFilename()) is the only way to check if a method was defined inside of a trait. |
when parsing use statements from classes which use traits, the traits itself are not parsed.
this PR adds the missing trait parsing for php >= 5.4.
unit tests included.