TemplateLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 1
b 0
f 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 18 4
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerChangelogs\Loaders;
7
8
class TemplateLoader implements \Mustache_Loader
9
{
10
    /**
11
     * @var array
12
     */
13
    private $content = array();
14
15
    /**
16
     * @var \Closure
17
     */
18
    private $pathResolver;
19
20
    public function __construct(
21
        ?\Closure $pathResolver = null
22
    ) {
23
        $this->pathResolver = $pathResolver;
24
    }
25
26
    public function load($path)
27
    {
28
        if ($this->pathResolver !== null) {
29
            $resolver = $this->pathResolver;
30
            $path = $resolver($path);
31
        }
32
        
33
        if (!isset($this->content[$path])) {
34
            if (!file_exists($path)) {
35
                $message = sprintf('Could not find template file %s', $path);
36
                
37
                throw new \Vaimo\ComposerChangelogs\Exceptions\LoaderException($message);
38
            }
39
40
            $this->content[$path] = file_get_contents($path);
41
        }
42
43
        return $this->content[$path];
44
    }
45
}
46