DefaultLayoutRenderTemplate::renderTemplate()   A
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
nc 3
nop 2
dl 0
loc 17
ccs 10
cts 10
cp 1
crap 6
rs 9.0777
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\Extension\LayoutSections;
4
5
use League\Plates;
6
7
final class DefaultLayoutRenderTemplate extends Plates\RenderTemplate\RenderTemplateDecorator
8
{
9
    private $layout_path;
10
11 12
    public function __construct(Plates\RenderTemplate $render, $layout_path) {
12 12
        parent::__construct($render);
13 12
        $this->layout_path = $layout_path;
14 12
    }
15
16 12
    public function renderTemplate(Plates\Template $template, Plates\RenderTemplate $rt = null) {
17 12
        if ($template->parent || $template->get('no_layout')) {
18 12
            return $this->render->renderTemplate($template, $rt ?: $this);
19
        }
20
21 8
        $ref = $template->reference;
22 8
        $contents = $this->render->renderTemplate($template, $rt ?: $this);
23
24 8
        if ($ref()->get('layout')) {
25 4
            return $contents;
26
        }
27
28 4
        $layout = $ref()->fork($this->layout_path);
29 4
        $ref()->with('layout', $layout->reference);
30
31 4
        return $contents;
32
    }
33
34
    public static function factory($layout_path) {
35 12
        return function(Plates\RenderTemplate $rt) use ($layout_path) {
36 12
            return new self($rt, $layout_path);
37 12
        };
38
    }
39
}
40
41
42