DefaultLayoutRenderTemplate   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B renderTemplate() 0 17 6
A factory() 0 5 1
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