Skip to content

Commit

Permalink
Leverage arrow function syntax for closure
Browse files Browse the repository at this point in the history
  • Loading branch information
tigitz authored and nicolas-grekas committed Jan 13, 2023
1 parent 0dd4f98 commit 6358546
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 6358546

Please sign in to comment.