Completed
Push — feature/sass-standard ( 649e69...554da1 )
by Vladimir
12:12
created

EvaluateFilter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 19
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 6 1
A get() 0 9 1
1
<?php
2
3
namespace BZIon\Twig;
4
5
/**
6
 * A Twig filter that takes a string Twig template and an array for context and renders it.
7
 *
8
 * i.e. A Twig filter to render Twig from inside of Twig
9
 */
10
class EvaluateFilter
11
{
12
    public function __invoke(\Twig_Environment $env, $string, array $context)
13
    {
14
        $template = $env->createTemplate($string);
15
16
        return $template->render($context);
17
    }
18
19
    public static function get()
20
    {
21
        return new \Twig_SimpleFilter('evaluate', new self(), [
22
            'needs_environment' => true,
23
            'is_safe' => [
24
                'evaluate' => true
25
            ]
26
        ]);
27
    }
28
}
29