-
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
Fix for issue #81 Traits Composed from Traits #102
Conversation
Use statements are now also imported for properties and methods from traits in traits. Conflict resolution and aliases are respected. For backwards compatibility reasons the use statements from the declaring class are still merged. PHP itself does not show this behaviour regarding to imported types in traits.
It would be great to get this merged if possible. It's a very annoying bug. |
It's been just shy of 2 years since this was submitted. Is there anything we can do to help get this merged? |
I simply completely missed this (among the 186 open PRs I'm mentioned in). Keeping a tab open, can't promise much. |
@Ocramius, thanks for the quick reply. I can totally understand if this task got forgotten due to other tasks taking priority. This bug is probably a lower priority since there's a workaround to add Apologies if I seemed too blunt, but I'm glad this is at least back on your radar and I understand if it's still lesser priority than others. Let me know if I can help. Thanks! :) |
@Ocramius I think this PR should have a higher priority now, bcz the use of tools like php cs fixer has become democratized. Thx. |
This is what PHPStan is using, we should use something similar or based on that: https://github.com/phpstan/phpstan/blob/0.10.6/src/Reflection/Php/PhpClassReflectionExtension.php#L365-L437 |
Ok, this gets REALLY tricky when only using PHP's Reflection:
I don't think support for traits is deterministically doable without introspecting the code itself using Nikic's PHP Parser (which is something I would like to avoid, but am open to do since it would also be useful for |
If we can keep I realise many folks rely on them, but they are really really messy overall. If we can harden the tests well enough to support all edge cases, then fine, but otherwise we shouldn't ship something half-baked. |
The baseline is: loads and loads of test scenarios for the traits (for properties, methods and class-level annotations), for following scenarios (which are the ones I can think of immediately):
|
Problem is that we can't even reliably leave traits out of equation. Unless you bail out immediately when a class |
Current behaviour is IMO even worse: it ignores |
Fix for issue #81
Use statements are now also imported for properties
and methods from traits in traits. Conflict resolution
and aliases are respected.
For backwards compatibility reasons the use statements
from the declaring class are still merged. PHP itself
does not show this behaviour regarding to imported types
in traits.
For the methods in traits I use
\ReflectionMethod::getFileName()
and then parse the file since this is the only way I can think of to
get the right declaration location in the face of imported traits using
conflict resolution. This same method is also possible for the
properties if you would prefer it.