Coding-standard: UselessParentheses false positive with arrow functions (PHP 7.4)

Created on 23 Jul 2019  路  4Comments  路  Source: slevomat/coding-standard

Starting with PHP 7.4 we'll have the ability to create arrow functions. The stable version will be available at the end of the year, but right now I'm testing the alpha2 release.

An arrow function with only one argument triggers a unwanted error Useless parentheses (SlevomatCodingStandard.PHP.UselessParentheses.UselessParentheses):

$firstName = 'John';
$name  = fn($firstName) => 'FirstName: ' . $firstName;

Zero or two or more arguments does not trigger an error - as expected.

// arrow function without arguments
$fullName = fn() => 'John Doe';

// arrow function with two or more arguments
$firstName = 'John';
$lastName  = 'Doe';
$fullName  = fn($firstName, $lastName) => $firstName . $lastName;

Environment:

  • PHP: PHP 7.4.0alpha2 (cli) (built: Jul 12 2019 01:56:19)
  • phpcs: PHP_CodeSniffer version 3.4.2 (stable)
  • slevomat/coding-standard: 5.0.4
Bug

All 4 comments

looks that the phpcs issue is closed now

Fixed in master.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dereuromark picture dereuromark  路  3Comments

janedbal picture janedbal  路  5Comments

Stadly picture Stadly  路  6Comments

carusogabriel picture carusogabriel  路  4Comments

Majkl578 picture Majkl578  路  3Comments