Skip to content

Commit ff84324

Browse files
committed
ExprCacheHelper: Reduce PHPParser instantiation
1 parent e124747 commit ff84324

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/Reflection/ExprCacheHelper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
final class ExprCacheHelper
1111
{
12+
private static BetterReflection $betterReflection;
1213

1314
/**
1415
* @return array<string, mixed
1516
*/
1617
public static function export(Expr $expr): array
1718
{
18-
$br = new BetterReflection();
19+
$br = self::$betterReflection ??= new BetterReflection();
1920

2021
$attributes = [];
2122
foreach (['startLine', 'endLine', 'startTokenPos', 'startFilePos', 'endTokenPos', 'endFilePos'] as $key) {
@@ -33,7 +34,7 @@ public static function import(array $data): Expr
3334
$code = $data['code'];
3435
$attributes = $data['attributes'];
3536

36-
$br = new BetterReflection();
37+
$br = self::$betterReflection ??= new BetterReflection();
3738
$expr = $br->originalPhpParser()->parse('<?php ' . $code . ';')[0]->expr;
3839
foreach ($attributes as $key => $value) {
3940
$expr->setAttribute($key, $value);

0 commit comments

Comments
 (0)