TemplateLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 0 13 3
1
<?php
2
3
/*
4
 * This file is part of the SexyField package.
5
 *
6
 * (c) Dion Snoeijen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare (strict_types = 1);
13
14
namespace Tardigrades\SectionField\Generator\Loader;
15
16
class TemplateLoader
17
{
18
    public static function load(string $location, array $variables = []): string
19
    {
20
        if (\file_exists($location)) {
21
            if (pathinfo($location, PATHINFO_EXTENSION) === 'php') {
22
                ob_start();
23
                extract($variables);
24
                include $location;
25
                return ob_get_clean();
26
            } else {
27
                return \file_get_contents($location);
28
            }
29
        }
30
        throw new TemplateNotFoundException($location . ': template not found');
31
    }
32
}
33