LayoutRenderTemplate::factory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\Extension\LayoutSections;
4
5
use League\Plates;
6
7
final class LayoutRenderTemplate extends Plates\RenderTemplate\RenderTemplateDecorator
8
{
9 28
    public function renderTemplate(Plates\Template $template, Plates\RenderTemplate $rt = null) {
10 28
        $ref = $template->reference;
11 28
        $content = $this->render->renderTemplate($template, $rt ?: $this);
12
13 28
        $layout_ref = $ref()->get('layout');
14 28
        if (!$layout_ref) {
15 28
            return $content;
16
        }
17
18 16
        $layout = $layout_ref()->with('sections', $ref()->get('sections'));
19 16
        $layout->get('sections')->add('content', $content);
20
21 16
        return ($rt ?: $this)->renderTemplate($layout);
22
    }
23
24
    public static function factory() {
25 24
        return function(Plates\RenderTemplate $render) {
26 24
            return new static($render);
27 24
        };
28
    }
29
}
30
31
32