-
Notifications
You must be signed in to change notification settings - Fork 79
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
Pick up docs for filters in condition expressions #186
base: master
Are you sure you want to change the base?
Conversation
PHPParser loops over the body of a conditional statement (the part between the curly brackets), before looping over each node in the expression. Because we were only saving the last docblock that wasn't associated with a documentable element, if there was also a documented filter within the condition body, the docblock for that filter would be picked up, and the docblock for the first filter in the condition expression would be discarded. So by the time we got to the node for the filter in the condition expression, there was no docblock saved to associate with it. This is now fixed by keeping a stack of stray docblocks for non-documentable elements, so that instead of the docblock for the first filter being discarded it is just pushed down the stack. The docblock for the second filter within the condition block will be pushed on top of it, and then popped off once it has been used. So when we come around to actually looping over the node for the filter in the conditional expression, its docblock will be at the tip of the stack once again, and can be associated with the filter as expected. See WordPress#185
Discovered while working on WordPress#185.
It looks like the tests are failing on PHP 7, but I don't think that is related to this PR. If I get a chance I'll investigate further, and see if I can find the cause of the problem. |
The error the tests are getting is this:
However, public function __construct(
$docblock,
Context $context = null,
Location $location = null
) { So an object is definitely being expected here. The only thing that I can think is that this error stems from a bug in PHP 7. |
As PHP 7.1 has been released it would be good to add it to the travis list and see if it passes there. |
This does not pass on PHP 7.1 either, has the same issues. I don't know what is going on here, I cannot reproduce this locally:
Which is the same configuration of PHP running on Travis. So I'm stumped. |
I've just added PRs for PHP 7.1 and to HHVM (Update HHVM to the latest) |
PHPParser loops over the body of a conditional statement (the part between the curly brackets), before looping over each node in the expression. Because we were only saving the last docblock that wasn't associated with a documentable element, if there was also a documented filter within the condition body, the docblock for that filter would be picked up, and the docblock for the first filter in the condition expression would be discarded. So by the time we got to the node for the filter in the condition expression, there was no docblock saved to associate with it.
This is now fixed by keeping a stack of stray docblocks for non-documentable elements, so that instead of the docblock for the first filter being discarded it is just pushed down the stack. The docblock for the second filter within the condition block will be pushed on top of it, and then popped off once it has been used. So when we come around to actually looping over the node for the filter in the conditional expression, its docblock will be at the tip of the stack once again, and can be associated with the filter as expected.
See #185