SmartyRenderer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 40
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A __invoke() 0 16 1
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