Skip to content
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

Suggestion: lower severity for unused variable if followed by include/require #105

Closed
jrfnl opened this issue Jan 15, 2020 · 1 comment · Fixed by #196
Closed

Suggestion: lower severity for unused variable if followed by include/require #105

jrfnl opened this issue Jan 15, 2020 · 1 comment · Fixed by #196
Milestone

Comments

@jrfnl
Copy link
Collaborator

jrfnl commented Jan 15, 2020

function name( $param ) {
    $var = 'something';
    require_once __DIR__ . '/views/my-view.php';
}

The above code currently generated an Unused function parameter and an Unused variable $var warning, however, as there is a require in the function, the parameter and the variable may well be (and are) used in the included file.

I'd suggest lowering the severity in that case to 4. That means that in a normal PHPCS run it will not show up, though can be made to show with --severity=4.

Alternatively a separate error code or a configurable property could possibly be used to prevent/silence these type of false positives.

Note: the below code sample should still throw an error/warning.

function name() {
    require_once __DIR__ . '/views/my-view.php';

    $var = 'something'; // Unused and as declared *after* the include, it cannot be used in the included file.
}
@sirbrillig
Copy link
Owner

This is a good idea, and thank you for the suggestions. A configurable property would be the easiest as it wouldn't be a breaking change. Perhaps we could start with that and see how it works, then we could try the other options in a future version.

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

Successfully merging a pull request may close this issue.

2 participants