Skip to content

Commit

Permalink
minor #48793 Leverage arrow function syntax for closure (tigitz)
Browse files Browse the repository at this point in the history
This PR was merged into the 6.3 branch.

Discussion
----------

Leverage arrow function syntax for closure

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #47658 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT
| Doc PR        | <!-- required for new features -->

Rationale in the RFC [here](https://wiki.php.net/rfc/arrow_functions_v2#introduction)

It's also notable that using arrow function syntax rather than the classic one has been enforced in the past by symfony core member: symfony/symfony#48069 (comment)

So this PR would be consistent.

Commits
-------

f5802d3a2a Leverage arrow function syntax for closure
  • Loading branch information
nicolas-grekas committed Jan 13, 2023
2 parents bf1b9d4 + 952d70d commit 9136206
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
4 changes: 1 addition & 3 deletions Node/FunctionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public function getSpecificity(): Specificity

public function __toString(): string
{
$arguments = implode(', ', array_map(function (Token $token) {
return "'".$token->getValue()."'";
}, $this->arguments));
$arguments = implode(', ', array_map(fn (Token $token) => "'".$token->getValue()."'", $this->arguments));

return sprintf('%s[%s:%s(%s)]', $this->getNodeName(), $this->selector, $this->name, $arguments ? '['.$arguments.']' : '');
}
Expand Down
4 changes: 1 addition & 3 deletions Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public static function parseSeries(array $tokens): array
}
}

$joined = trim(implode('', array_map(function (Token $token) {
return $token->getValue();
}, $tokens)));
$joined = trim(implode('', array_map(fn (Token $token) => $token->getValue(), $tokens)));

$int = function ($string) {
if (!is_numeric($string)) {
Expand Down
4 changes: 1 addition & 3 deletions Tests/Parser/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public function testParser($source, $representation)
{
$parser = new Parser();

$this->assertEquals($representation, array_map(function (SelectorNode $node) {
return (string) $node->getTree();
}, $parser->parse($source)));
$this->assertEquals($representation, array_map(fn (SelectorNode $node) => (string) $node->getTree(), $parser->parse($source)));
}

/** @dataProvider getParserExceptionTestData */
Expand Down

0 comments on commit 9136206

Please sign in to comment.