coding-standards
coding-standards copied to clipboard
Lambdas are a thing now
I think the standard needs to be relaxed a little bit for lambdas (if possible). For example:
$mapped = array_map(function ($a) { return $a->prop; }, $someObjects);
Will produce two phpcs errors:
- Closing brace must be on a line by itself
- Each PHP statement must be on a line by itself
So then, you might try:
$mapped = array_map(function ($a) {
return $a->prop;
},
$someObjects
);
Which is already terrible but then you get:
- Opening parenthesis of a multi-line function call must be the last content on the line
- Closing brace indented incorrectly; expected 2 spaces, found 3
So you try:
$mapped = array_map(
function ($a) {
return $a->prop;
},
$someObjects
);
And somehow it works but it's hideous.
Technically it's related to PHPCS and the built-in rules that we borrow from. the rules that are thrown from the first code snip are PEAR.Functions.FunctionDeclaration.ContentAfterBrace Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore Generic.Formatting.DisallowMultipleStatements.SameLine
To solve this we likely need to open an issue with PHPCS relating to lambda parsing and possibly exclusions for lambdas (there might be an open issue with PHPCS on this to join in on).