Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
RenderException
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 fromThrowable
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Boiler\Exception;
6
7use Celemas\Boiler\Location;
8use Throwable;
9
10final class RenderException extends RuntimeException implements TemplateException
11{
12    public static function fromThrowable(string $path, Throwable $throwable): self
13    {
14        $location =
15            $throwable instanceof RuntimeException || $throwable instanceof LogicException
16                ? $throwable->location()
17                : null;
18        $location ??= Location::fromThrowable($path, $throwable);
19        $message = $location->line === null
20            ? "Template rendering error ({$path})"
21            : "Template rendering error at {$location}";
22
23        return new self(
24            $message . ': ' . $throwable->getMessage(),
25            previous: $throwable,
26            location: $location,
27        );
28    }
29}