From deea5f0c2ed3f0e6e55ca060b1888f9a3761f8f3 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Fri, 1 Sep 2023 23:03:25 +0200 Subject: [PATCH] Arrow functions --- src/Internal/ObjectExporter/ClosureExporter.php | 8 ++++---- src/VarExporter.php | 7 ++++--- tests/AbstractTestCase.php | 4 +--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Internal/ObjectExporter/ClosureExporter.php b/src/Internal/ObjectExporter/ClosureExporter.php index 03ce908..5ecdf10 100644 --- a/src/Internal/ObjectExporter/ClosureExporter.php +++ b/src/Internal/ObjectExporter/ClosureExporter.php @@ -147,10 +147,10 @@ private function getClosure( int $line, array $path ) : Node\Expr\Closure { - $finder = new FindingVisitor(function(Node $node) use ($line) : bool { - return ($node instanceof Node\Expr\Closure || $node instanceof Node\Expr\ArrowFunction) - && $node->getStartLine() === $line; - }); + $finder = new FindingVisitor( + fn(Node $node): bool => ($node instanceof Node\Expr\Closure || $node instanceof Node\Expr\ArrowFunction) + && $node->getStartLine() === $line + ); $traverser = new NodeTraverser(); $traverser->addVisitor($finder); diff --git a/src/VarExporter.php b/src/VarExporter.php index 21d6e4f..13fc356 100644 --- a/src/VarExporter.php +++ b/src/VarExporter.php @@ -98,9 +98,10 @@ public static function export($var, int $options = 0, int $indentLevel = 0) : st $export = implode(PHP_EOL, $lines); } else { $firstLine = array_shift($lines); - $lines = array_map(function ($line) use ($indentLevel) { - return str_repeat(' ', $indentLevel) . $line; - }, $lines); + $lines = array_map( + fn($line) => str_repeat(' ', $indentLevel) . $line, + $lines, + ); $export = $firstLine . PHP_EOL . implode(PHP_EOL, $lines); } diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index edcef7a..82e77a1 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -63,9 +63,7 @@ public function assertExportEquals(string $expected, $var, int $options = 0) : v */ public function assertExportThrows(string $expectedMessage, $var, int $options = 0) : void { - $expectedMessageRegExp = '/' . implode('.*', array_map(function(string $str) { - return preg_quote($str, '/'); - }, explode('*', $expectedMessage))) . '/'; + $expectedMessageRegExp = '/' . implode('.*', array_map(fn(string $str) => preg_quote($str, '/'), explode('*', $expectedMessage))) . '/'; $this->expectException(ExportException::class); $this->expectExceptionMessageMatches($expectedMessageRegExp);