Skip to content

Commit 25ab5d1

Browse files
committed
Fix: closure traces support
1 parent 43d8cc0 commit 25ab5d1

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

app/Processor.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,8 @@ private function getLine(): Generator
229229
assert($this->dataReader instanceof ReadableStream);
230230
foreach (splitLines($this->dataReader) as $line) {
231231
$line = trim($line);
232-
233-
//fix trace with eval
234-
if (strpos($line, ' : eval()\'d code:') !== false) {
235-
$line = preg_replace('~\((\d+)\) : eval\(\)\'d code:.*$~u', ':$1', $line);
236-
if ($line === null) {
237-
$line = 'eval() code replacement failure';
238-
}
239-
}
232+
$line = self::fixEvalLine($line);
233+
$line = self::fixClosureLine($line);
240234

241235
yield $line;
242236
}
@@ -267,4 +261,24 @@ private function countResults(): int
267261
}
268262
return $count;
269263
}
264+
265+
private static function fixEvalLine(string $line): string
266+
{
267+
268+
if (strpos($line, ' : eval()\'d code:') !== false) {
269+
$line = preg_replace('~\((\d+)\) : eval\(\)\'d code:.*$~u', ':$1', $line);
270+
if ($line === null) {
271+
$line = 'eval() code replacement failure';
272+
}
273+
}
274+
return $line;
275+
}
276+
277+
private static function fixClosureLine(string $line): string
278+
{
279+
if (preg_match('~({closure.*}):\d+~u', $line, $closure) && str_contains($closure[1], ' ')) {
280+
$line = str_replace($closure[1], sprintf("{closure:%s} <closure>", md5($closure[1])), $line);
281+
}
282+
return $line;
283+
}
270284
}

0 commit comments

Comments
 (0)