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

Unused parameter false positive when using array index in arrow function #3284

Closed
ghnp5 opened this issue Mar 29, 2021 · 2 comments
Closed
Milestone

Comments

@ghnp5
Copy link

ghnp5 commented Mar 29, 2021

Hello,

This works fine:

$found = in_array_cb($needle, $haystack, function($array, $needle) {
	return $array[2] === $needle;
});

But in the bellow, PHPCS complains with "The method parameter $needle is never used" (Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed):

$found = in_array_cb($needle, $haystack, fn($array, $needle) => $array[2] === $needle);

If I remove "[2]", PHPCS does not complain:

$found = in_array_cb($needle, $haystack, fn($array, $needle) => $array === $needle);
@gsherwood
Copy link
Member

Looks like this is caused by the T_FN end token matching, and something in the sniff itself. I've fixed the T_FN end token but still confirming that, and looking into the sniff.

@gsherwood gsherwood added this to the 3.6.0 milestone Mar 29, 2021
@gsherwood gsherwood changed the title Unused Parameter in Arrow function Unused parameter false positive when using array index in arrow function Mar 30, 2021
gsherwood added a commit that referenced this issue Mar 30, 2021
gsherwood added a commit that referenced this issue Mar 30, 2021
@gsherwood
Copy link
Member

I've pushed a fix for this now. Thanks for reporting it.

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

No branches or pull requests

2 participants