ValidatePathRenderTemplate::renderTemplate()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.128

Importance

Changes 0
Metric Value
cc 4
nc 2
nop 2
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 4.128
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\RenderTemplate;
4
5
use League\Plates;
6
7
final class ValidatePathRenderTemplate extends RenderTemplateDecorator
8
{
9
    private $file_exists;
10
11 24
    public function __construct(Plates\RenderTemplate $render, $file_exists = 'file_exists') {
12 24
        parent::__construct($render);
13 24
        $this->file_exists = $file_exists;
14 24
    }
15
16 24
    public function renderTemplate(Plates\Template $template, Plates\RenderTemplate $rt = null) {
17 24
        $path = $template->get('path');
18 24
        if (!$path || ($this->file_exists)($path)) {
19 24
            return $this->render->renderTemplate($template, $rt ?: null);
20
        }
21
22
        throw new Plates\Exception\RenderTemplateException('Template path ' . $path . ' is not a valid path for template: ' . $template->name);
23
    }
24
}
25