-
Notifications
You must be signed in to change notification settings - Fork 17
Closed
Description
PHP 7.4 introduces arrow functions. It would be great if this library would add support for these.
// Currently throwing false positives for undefined variables $a x 2, $b x 2, $c x 1.
$fn = fn($a, $b, $c) => $a + $b; // Unused $c (false negative).
function foo() {
$a = 120;
// Currently throwing false positive for undefined variable $b x 2.
$fn1 = fn($b) => $a + $b;
// Currently throwing false positive for undefined variable $b.
$fn2 = fn($b) => $a; // Unused $b (false negative).
// Currently throwing false positive for undefined variable $b x 2, $c x 1.
$fn3 = fn($b) => $b + $c; // Undefined $c (false negative). Unused variable $fn3 (correctly thrown).
var_dump( $fn1(10) );
var_dump( $fn2(10) );
}
Note: PHPCS itself doesn't properly support arrow functions until PHPCS 3.5.5 (not yet released).
If continued support for older PHPCS versions is desired, you may want to look at the PHPCSUtils
FunctionDeclarations::isArrowFunction()
and FunctionDeclarations::getArrowFunctionOpenClose()
methods.
Refs:
markjaquith, gertjankrol, Levivb and stefanfisk