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 74f03d4 + 6358546 commit e271327
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 12 deletions.
4 changes: 1 addition & 3 deletions Caster/ClassStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public function __construct(string $identifier, callable|array|string $callable
}

if (str_contains($identifier, "@anonymous\0")) {
$this->value = $identifier = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
}, $identifier);
$this->value = $identifier = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0], $identifier);
}

if (null !== $callable && $r instanceof \ReflectionFunctionAbstract) {
Expand Down
4 changes: 1 addition & 3 deletions Caster/ExceptionCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,7 @@ private static function filterExceptionArray(string $xClass, array $a, string $x
unset($a[$xPrefix.'string'], $a[Caster::PREFIX_DYNAMIC.'xdebug_message'], $a[Caster::PREFIX_DYNAMIC.'__destructorException']);

if (isset($a[Caster::PREFIX_PROTECTED.'message']) && str_contains($a[Caster::PREFIX_PROTECTED.'message'], "@anonymous\0")) {
$a[Caster::PREFIX_PROTECTED.'message'] = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
}, $a[Caster::PREFIX_PROTECTED.'message']);
$a[Caster::PREFIX_PROTECTED.'message'] = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0], $a[Caster::PREFIX_PROTECTED.'message']);
}

if (isset($a[Caster::PREFIX_PROTECTED.'file'], $a[Caster::PREFIX_PROTECTED.'line'])) {
Expand Down
4 changes: 1 addition & 3 deletions Tests/Cloner/VarClonerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,7 @@ public function testJsonCast()
public function testCaster()
{
$cloner = new VarCloner([
'*' => function ($obj, $array) {
return ['foo' => 123];
},
'*' => fn ($obj, $array) => ['foo' => 123],
__CLASS__ => function ($obj, $array) {
++$array['foo'];

Expand Down
4 changes: 1 addition & 3 deletions Tests/Command/Descriptor/CliDescriptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public function testDescribe(array $context, string $expectedOutput, bool $decor
{
$output = new BufferedOutput();
$output->setDecorated($decorated);
$descriptor = new CliDescriptor(new CliDumper(function ($s) {
return $s;
}));
$descriptor = new CliDescriptor(new CliDumper(fn ($s) => $s));

$descriptor->describe($output, new Data([[123]]), $context + ['timestamp' => 1544804268.3668], 1);

Expand Down

0 comments on commit e271327

Please sign in to comment.