SmartyRenderer::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 10
cp 0
rs 9.7333
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 SmartyRenderer implements RendererInterface, LoggerAwareInterface {
10
11
    use LoggerAwareTrait;
12
13
    /**
14
     * @var Smarty
15
     */
16
    public $smarty;
17
18
19
    /**
20
     * @param \Smarty              $smarty Your Smarty instance
21
     * @param LoggerInterface|null $logger Optional: PSR-3 Logger
22
     */
23
    public function __construct (\Smarty $smarty, LoggerInterface $logger = null )
24
    {
25
        $this->smarty = $smarty;
0 ignored issues
show
Documentation Bug introduced by
It seems like $smarty of type object<Smarty> is incompatible with the declared type object<Germania\Renderer\Smarty> of property $smarty.

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...
26
        $this->setLogger( $logger ?: new NullLogger );
27
    }
28
29
    /**
30
     * {@inheritDoc }
31
     */
32
    public function __invoke( $template, array $context = array())
33
    {
34
        $this->logger->info("Render Smarty template: " . $template, [
35
            'context'  => $context
36
        ]);
37
38
        $this->logger->debug("Create template object");
39
        $tpl = $this->smarty->createTemplate(  $template, $this->smarty );
40
41
        $this->logger->debug("Assign context variables");
42
        $tpl->assign( $context );
43
44
        $this->logger->info("Return template output");
45
46
        return $this->smarty->fetch($tpl);
47
    }
48
}
49