Passed
Pull Request — master (#6)
by James Ekow Abaka
02:52
created

Templates::appendPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
4
namespace ntentan\honam;
5
6
7
use ntentan\honam\TemplateFileResolver;
8
use ntentan\honam\TemplateRenderer;
9
use ntentan\honam\factories\PhpEngineFactory;
10
use ntentan\honam\factories\MustacheEngineFactory;
11
use ntentan\honam\engines\php\HelperVariable;
12
use ntentan\honam\engines\php\Janitor;
13
14
/**
15
 * An access point to most of the functionality in honam
16
 */
17
class Templates
18
{
19
    /**
20
     * An instance of the template renderer for rendering templates.
21
     * @var TemplateRenderer
22
     */
23
    private $templateRenderer;
24
    
25
    /**
26
     * An instance of the resolver that resolves template files for requests.
27
     * @var TemplateFileResolver
28
     */
29
    private $templateFileResolver;
30
    
31
    /**
32
     * An instance of the engine registry for loading template engines.
33
     * This engine registry is only used when an external template renderer is not supplied.
34
     * 
35
     * @var EngineRegistry
36
     */
37
    private $engineRegistry;
38
39
    public function __construct(TemplateFileResolver $templateFileResolver = null, TemplateRenderer $templateRenderer = null)
40
    {
41
        $this->templateFileResolver = $templateFileResolver ?? new TemplateFileResolver();
42
        $this->templateRenderer = $templateRenderer ?? new TemplateRenderer($this->engineRegistry = new EngineRegistry(), $this->templateFileResolver);
43
        if($this->engineRegistry) {
44
            $this->engineRegistry->registerEngine(['.mustache'], new MustacheEngineFactory($this->templateFileResolver));
45
            $helperVariable = new HelperVariable($this->templateRenderer, $this->templateFileResolver);
46
            $this->engineRegistry->registerEngine(['.tpl.php'], new PhpEngineFactory($this->templateRenderer, $helperVariable, new Janitor()));
47
        }
48
    }
49
50
    public function prependPath(string $path)
51
    {
52
        $this->templateFileResolver->prependToPathHierarchy($path);
53
    }
54
55
    public function appendPath(string $path)
56
    {
57
        $this->templateFileResolver->appendPath($path);
0 ignored issues
show
Bug introduced by
The method appendPath() does not exist on ntentan\honam\TemplateFileResolver. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        $this->templateFileResolver->/** @scrutinizer ignore-call */ 
58
                                     appendPath($path);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
    }
59
60
    public function render(string $template, array $data)
61
    {
62
        return $this->templateRenderer->render($template, $data);
63
    }
64
}
65