Completed
Pull Request — master (#75)
by Vladimir
02:24
created

TwigTemplate   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 53.85%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 40
ccs 7
cts 13
cp 0.5385
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTemplateName() 0 4 1
A render() 0 4 1
A getParentTemplate() 0 11 2
1
<?php
2
3
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/stakx-io/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Templating\Twig;
9
10
use allejo\stakx\Templating\TemplateInterface;
11
12
class TwigTemplate implements TemplateInterface
13
{
14
    private $template;
15
16 12
    public function __construct(\Twig_Template $template)
17
    {
18 12
        $this->template = $template;
19 12
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 12
    public function getTemplateName()
25
    {
26 12
        return $this->template->getTemplateName();
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getParentTemplate()
33
    {
34
        $parent = $this->template->getParent([]);
35
36
        if ($parent === false)
37
        {
38
            return false;
39
        }
40
41
        return new TwigTemplate($parent);
0 ignored issues
show
Compatibility introduced by
$parent of type object<Twig_TemplateInterface> is not a sub-type of object<Twig_Template>. It seems like you assume a concrete implementation of the interface Twig_TemplateInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 12
    public function render(array $context = [])
48
    {
49 12
        return $this->template->render($context);
50
    }
51
}
52