Conditions | 7 |
Paths | 12 |
Total Lines | 37 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 23 |
CRAP Score | 7 |
Changes | 0 |
1 | <?php |
||
18 | 3 | public function mapException(\Throwable $e, string $class, string $filename, array $data): \Throwable |
|
19 | { |
||
20 | 3 | $line = $e->getLine(); |
|
21 | 3 | $classFilename = (new \ReflectionClass($class))->getFileName(); |
|
22 | |||
23 | // looking for proper view error location |
||
24 | 3 | if ($e->getFile() !== $classFilename) { |
|
25 | 1 | foreach ($e->getTrace() as $trace) { |
|
26 | 1 | if (isset($trace['file']) && $trace['file'] === $classFilename) { |
|
27 | 1 | $line = $trace['line']; |
|
28 | 1 | break; |
|
29 | } |
||
30 | } |
||
31 | } |
||
32 | |||
33 | 3 | $userStack = []; |
|
34 | 3 | foreach ($this->sourcemap->getStack($line - $this->lineOffset) as $stack) { |
|
35 | 3 | $userStack[] = [ |
|
36 | 3 | 'file' => $stack['file'], |
|
37 | 3 | 'line' => $stack['line'], |
|
38 | 3 | 'class' => StemplerEngine::class, |
|
39 | 3 | 'type' => '->', |
|
40 | 3 | 'function' => 'render', |
|
41 | 3 | 'args' => [$data], |
|
42 | 3 | ]; |
|
43 | |||
44 | 3 | if ($stack['file'] === $filename) { |
|
45 | // no need to jump over root template |
||
46 | 3 | break; |
|
47 | } |
||
48 | } |
||
49 | |||
50 | |||
51 | 3 | $e = new RenderException($e); |
|
52 | 3 | $e->setUserTrace($userStack); |
|
53 | |||
54 | 3 | return $e; |
|
55 | } |
||
57 |