Completed
Push — extensions ( 84a6ae )
by
unknown
22:00 queued 07:01
created

PhpRenderTemplate::renderTemplate()   B

Complexity

Conditions 5
Paths 10

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 10
nop 2
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\RenderTemplate;
4
5
use League\Plates;
6
7
final class PhpRenderTemplate implements Plates\RenderTemplate
8
{
9
    private $bind;
10
11
    public function __construct(callable $bind = null) {
12
        $this->bind = $bind;
13
    }
14
15
    public function renderTemplate(Plates\Template $template, Plates\RenderTemplate $render = null) {
16
        $inc = self::createInclude();
17
        $inc = $this->bind ? ($this->bind)($inc, $template) : $inc;
18
19
        $cur_level = ob_get_level();
20
        try {
21
            return $inc($template->get('path'), $template->data);
22
        } catch (\Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
23
          catch (\Throwable $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
24
25
        // clean the ob stack
26
        while (ob_get_level() > $cur_level) {
27
            ob_end_clean();
28
        }
29
30
        throw $e;
31
    }
32
33
    private static function createInclude() {
34
        return function() {
35
            ob_start();
36
            extract(func_get_arg(1));
0 ignored issues
show
Bug introduced by
func_get_arg(1) cannot be passed to extract() as the parameter $var_array expects a reference.
Loading history...
37
            include func_get_arg(0);
38
            return ob_get_clean();
39
        };
40
    }
41
}
42