TemplateRenderer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A renderTemplate() 0 12 2
1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Http\Router\Helper;
15
16
use Throwable;
17
18
use function extract;
19
use function ob_end_clean;
20
use function ob_get_clean;
21
use function ob_start;
22
23
/**
24
 * @since 3.0.0
25
 */
26
final class TemplateRenderer
27
{
28
    /**
29
     * @param array<string, mixed> $variables
30
     */
31 2
    public static function renderTemplate(string $filename, array $variables): string
32
    {
33 2
        extract($variables);
34 2
        ob_start();
35
36
        try {
37 2
            include $filename;
38
            /** @var string */
39 1
            return ob_get_clean();
40 1
        } catch (Throwable $e) {
41 1
            ob_end_clean();
42 1
            throw $e;
43
        }
44
    }
45
}
46