-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Generic/UnusedFunctionParameter: improve code coverage #249
Generic/UnusedFunctionParameter: improve code coverage #249
Conversation
5009265
to
d6998ac
Compare
@rodrigoprimo This may just have been an oversight when the sniff was originally created, though I'm not sure it is. Keep in mind that the sniff cannot check whether a method being implemented is an interface method as it doesn't have access to the method names expected by the interface, it can only make assumptions based on common code patterns. Note: might be an idea to open an issue for questions like this instead of tightly coupling them to a pull request, which can delay the pull request (as the question would need to be answered before the PR can be merged). |
Pro-tip: when posting code samples, add the language after the triple backtick to allow GH to highlight the code for better readability. I.e. |
To add more tests with syntax errors in separate files in subsequent commits.
I found this while working on improving code coverage for this sniff. The value of this variable is defined again on line 112 and then only used right below it on line 113 (https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/84acf4e56f110db8e75cb9a575c5727df637643c/src/Standards/Generic/Sniffs/CodeAnalysis/UnusedFunctionParameterSniff.php#L112-L113) so it should be safe to remove it.
This commit renames `$tmp` variables using more descriptive names to make it easier to understand the code.
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.
Thanks @rodrigoprimo ! LGTM.
I'll rebase the PR (without changes) before merging it.
For the future - when making functional changes, please explain those briefly in the PR description instead of pointing to a commit message.
(or include commit message(s) in the PR description)
At this point in the code, there should always be a non-empty token after the return statement, even if only the scope closer, and thus the if condition will never be true. If there is a syntax error and there is nothing after the return, the code will never reach this point as in the beginning of the method the code checks if `$token['scope_opener']` is set and this only happens when there is also a scope_closer.
d6998ac
to
e881193
Compare
Actually... I'm making one small change and that's removing a comment which is redundant in the last commit. |
Description
This PR improves the code coverage for the Generic.CodeAnalysis.UnusedFunctionParameter sniff.
It also includes three commits that change the sniff code directly.
The first commit removes an unused variable.
The second commit renames two
$tmp
variables to have more descriptive names (the new names are a bit long, so I ended up splitting two lines into multiple lines to improve the readability of the code).The third commit removes an if condition that, as far as I could check, is not reachable. More information is in the commit message.
Happy to drop those three commits as they are outside of the scope of #146.
I might be missing something, but while working on the new tests, I noticed that the following code triggers the sniff while I believe it should not trigger it:
The sniff is not triggered for methods that are part of a class that implements an interface and that return on the first line. Is there are reason that I'm missing that would justify triggering this sniff for such methods when there is more than one non-empty token between the return statement and the semicolon?
Related issues/external references
Part of #146
Types of changes
PR checklist