-
-
Notifications
You must be signed in to change notification settings - Fork 89
Handle parse error in File::getMethodProperties() #1350
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
base: 4.x
Are you sure you want to change the base?
Handle parse error in File::getMethodProperties() #1350
Conversation
While investigating the cause of a PHP Fatal error while processing some input in the `PSR12.Functions.ReturnTypeDeclaration` sniff, I noticed that the `File::getMethodProperties()` method did not return sensible values in for some parse errors. The input file in question was `src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.2.inc`, which contains an intentional parse error. The `File::getMethodProperties()` method claimed that the return type of the `test` function was `<< HEAD`, which is nonsense. The change in this commit safeguards from such parse errors and resolves the issue that was being encountered downstream in the sniff.
|
@fredden Thanks for creating this PR. I'm currently looking at the conflict you identified and I'm not so sure this is the correct solution as it changes a return value which is valid (
|
Reading the code with fresh eyes, it seems like this is a sensible suggestion. I think I dismissed this due to the need to skip over
Yes, that was where I started. When I realised that the sniff was relying on the output from It should be easy to add some validation to the sniff to cover the case where |
|
I have opened #1354 to add some defensive coding to the sniff that started this journey. For the |
The most straight-forward way to add these would be by adding more test classes with their own Mind - PHPCSUtils has a shadow-method for the Might be worth porting that one over from Utils to PHPCS before adding more parse error tests for this method. |
Description
While investigating the cause of a PHP Fatal error while processing some input in the
PSR12.Functions.ReturnTypeDeclarationsniff, I noticed that theFile::getMethodProperties()method did not return sensible values in for some parse errors. The input file in question wassrc/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.2.inc, which contains an intentional parse error. TheFile::getMethodProperties()method claimed that the return type of thetestfunction was<< HEAD, which is nonsense.The change in this commit safeguards from such parse errors and resolves the issue that was being encountered downstream in the sniff.
Suggested changelog entry
Handle parse error in File::getMethodProperties()
Related issues/external references
Relates to #152
Types of changes
PR checklist