TwigRenderer::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 7
cp 0
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
namespace Germania\Renderer;
3
4
use \Psr\Log\LoggerInterface;
5
use \Psr\Log\LoggerAwareTrait;
6
use \Psr\Log\LoggerAwareInterface;
7
use \Psr\Log\NullLogger;
8
9
class TwigRenderer implements RendererInterface, LoggerAwareInterface {
10
11
    use LoggerAwareTrait;
12
13
    /**
14
     * @var Twig_Environment
15
     */
16
    public $twig;
17
18
    /**
19
     * @param \Twig_Environment    $twig   Your Twig_Environment instance
20
     * @param LoggerInterface|null $logger Optional: PSR-3 Logger
21
     */
22
    public function __construct (\Twig_Environment $twig, LoggerInterface $logger = null )
23
    {
24
        $this->twig = $twig;
0 ignored issues
show
Documentation Bug introduced by
It seems like $twig of type object<Twig_Environment> is incompatible with the declared type object<Germania\Renderer\Twig_Environment> of property $twig.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
25
        $this->setLogger( $logger ?: new NullLogger );
26
    }
27
28
    /**
29
     * {@inheritDoc }
30
     */
31
    public function __invoke( $template, array $context = array())
32
    {
33
        $this->logger->info("Render Twig template: " . $template, [
34
            'context'  => $context
35
        ]);
36
37
        $result = $this->twig->render($template, $context );
38
39
        $this->logger->info("Return template output");
40
41
        return $result;
42
43
    }
44
}
45