8000 Fix node being undetected as part of function signature when too deeply nested. by niconoe- · Pull Request #1847 · infection/infection · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix node being undetected as part of function signature when too deeply nested. #1847

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

Merged
merged 2 commits into from
Apr 25, 2023

Conversation

niconoe-
Copy link
Contributor

This PR:

To detect if a Node is part of a signature of a function/method, it used to be checked if that Node is a "function-like" Node or if its direct parent is a Node\Param.
With the usage of PHP Attributes, Nodes to check can be more deeply nested, and looking at the direct parent is no longer sufficient.
This PR ensures that all ancestors are being parsed until a Node\Param is found, or no more parent exists.

Copy link
Member
@sanmai sanmai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change to the visitor makes sense, but I didn't quite get the tests (probably because I'm too tired)

@sanmai sanmai requested a review from maks-rafalko April 25, 2023 14:08
@niconoe-
Copy link
Contributor Author

The change to the visitor makes sense, but I didn't quite get the tests (probably because I'm too tired)

I basically copy-pasted the integration test "ReflectionVisitorTest::test_it_marks_nodes_which_are_part_of_the_function_signature", but I added an attribute with a "Node\Expr\ConstFetch" element within in the duplicated test. As this node is actually part of the method signature, we expect true, but it cannot be detected as part of the method signature without my fix: the parent's node is not a "Node\Param" while it has an ancestor which is a "Node\Param".

In a clearer way, you can try with the Unit Test I added without the source code edition and you'll see that the dataset with the provider about the "Node\Expr\ConstFetch" node won't pass the test, while when applying my fix, it passes. 🙂

Copy link
Member
@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spent a couple of minutes with tests and yeah, they do make sense, as well as the source code change.

I absolutely appreciate your time debugging Infection and finding the root cause and fixing it, thank you.

@maks-rafalko maks-rafalko merged commit 9bbe499 into infection:master Apr 25, 2023
@maks-rafalko
Copy link
Member

Regarding the differencies on Playground before and after update: I believe this is related to different versions of PHP (8.0 before, 8.1 currently), PHPUnit (9.5 before, 10.1 currently). Because too much has changed related to coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0