Skip to content

Commit 71c8b93

Browse files
committed
extract location for evald exception source
1 parent 0b7ee40 commit 71c8b93

3 files changed

Lines changed: 10 additions & 13 deletions

File tree

src/Handlers/Console.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function handleStack(Trace $trace): void
6868
$this->writeln($indent.$exception->getFile().':'.$exception->getLine());
6969
$this->writeln('');
7070

71-
foreach ($trace->getContext()->getPlaceInFile() as $num => $line) {
71+
foreach ($trace->getFrames()[0]->getPlaceInFile() as $num => $line) {
7272
$lineIndent = $doubleIndent;
7373

7474
if ($num === $trace->getException()->getLine()) {

src/Inspection/Frame.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ class Frame
2323

2424
public static function create(array $frame): self
2525
{
26+
// @link https://github.com/symfony/var-dumper/commit/7670e4790f447b3380993b8109ae2ed3d2366480
27+
if (preg_match('/\((\d+)\)(?:\([\da-f]{32}\))? : (?:eval\(\)\'d code|runtime-created function)$/', $frame['file'] ?? '', $match) !== false) {
28+
$frame['file'] = substr($frame['file'], 0, -\strlen($match[0]));
29+
$frame['line'] = (int) $match[1];
30+
}
31+
2632
$caller = $frame['function'] ?? '(unknown)';
33+
2734
if (isset($frame['class'], $frame['type'])) {
2835
$caller = $frame['class'].$frame['type'].$frame['function'];
2936
}
37+
3038
return new self($frame['file'] ?? null, $frame['line'] ?? null, $caller, $frame['args'] ?? []);
3139
}
3240

src/Inspection/Trace.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,8 @@ public function getExceptionClassName(): string
2525
return \get_class($this->exception);
2626
}
2727

28-
public function getContext(): Context
29-
{
30-
return new Context($this->exception->getFile(), $this->exception->getLine());
31-
}
32-
3328
public function getFrames(): array
3429
{
35-
$frames = [];
36-
37-
foreach ($this->exception->getTrace() as $params) {
38-
$frames[] = Frame::create($params);
39-
}
40-
41-
return $frames;
30+
return array_map(fn (array $params): Frame => Frame::create($params), $this->exception->getTrace());
4231
}
4332
}

0 commit comments

Comments
 (0)