Completed
Push — dev ( 25448e...6b3af8 )
by James Ekow Abaka
02:59
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\engines\PhpEngine;
10
use ntentan\honam\engines\MustacheEngine;
11
12
class Templates
13
{
14
    private $templateRenderer;
15
    private $templateFileResolver;
16
17
    public function __construct(TemplateFileResolver $templateFileResolver = null, TemplateRenderer $templateRenderer = null)
18
    {
19
        $engineRegistry = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $engineRegistry is dead and can be removed.
Loading history...
20
        $this->templateFileResolver = $templateFileResolver ?? new TemplateFileResolver();
21
        $this->templateRenderer = $templateRenderer ?? new TemplateRenderer($engineRegistry = new EngineRegistry(), $templateFileResolver);
0 ignored issues
show
Bug introduced by
It seems like $templateFileResolver can also be of type null; however, parameter $templateFileResolver of ntentan\honam\TemplateRenderer::__construct() does only seem to accept ntentan\honam\TemplateFileResolver, maybe add an additional type check? ( Ignorable by Annotation )

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

21
        $this->templateRenderer = $templateRenderer ?? new TemplateRenderer($engineRegistry = new EngineRegistry(), /** @scrutinizer ignore-type */ $templateFileResolver);
Loading history...
22
        if($engineRegistry) {
23
            $engineRegistry->registerEngine('mustache', new MustacheEngine());
0 ignored issues
show
Bug introduced by
The call to ntentan\honam\engines\Mu...heEngine::__construct() has too few arguments starting with stringRenderingEngine. ( Ignorable by Annotation )

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

23
            $engineRegistry->registerEngine('mustache', /** @scrutinizer ignore-call */ new MustacheEngine());

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
24
            $engineRegistry->registerEngine('php.tpl', new PhpEngine());
0 ignored issues
show
Bug introduced by
The call to ntentan\honam\engines\PhpEngine::__construct() has too few arguments starting with templateRenderer. ( Ignorable by Annotation )

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

24
            $engineRegistry->registerEngine('php.tpl', /** @scrutinizer ignore-call */ new PhpEngine());

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
25
        }
26
    }
27
28
    public function prependPath(string $path)
29
    {
30
        $this->templateFileResolver->prependToPathHierarchy($path);
31
    }
32
33
    public function appendPath(string $path)
34
    {
35
        $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

35
        $this->templateFileResolver->/** @scrutinizer ignore-call */ 
36
                                     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...
36
    }
37
38
    public function render(string $template, array $data)
39
    {
40
        return $this->templateRenderer->render($template, $data);
41
    }
42
}
43