Completed
Pull Request — master (#1)
by Mathieu
04:21
created

PhpEngine   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 4 1
A renderTemplate() 0 14 1
1
<?php
2
3
namespace Charcoal\View\Php;
4
5
use \InvalidArgumentException;
6
7
// Intra-module (`charcoal-view`) depentencies
8
use \Charcoal\View\AbstractEngine;
9
10
/**
11
 *
12
 */
13
class PhpEngine extends AbstractEngine
14
{
15
    /**
16
     * @return string
17
     */
18
    public function type()
19
    {
20
        return 'php';
21
    }
22
23
    /**
24
     * @param string $templateString The template string to render.
25
     * @param mixed  $context        The rendering context.
26
     * @return string The rendered template string.
27
     */
28
    public function renderTemplate($templateString, $context)
29
    {
30
        // Prevents leaking global variable by forcing anonymous scope
31
        $render = function($templateString, $context) {
32
            extract($context);
33
            return eval('?>'.$templateString);
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
34
        };
35
36
        ob_start();
37
        $render($templateString, $context);
38
        $output = ob_get_clean();
39
40
        return $output;
41
    }
42
}
43