TFile::loadTemplate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace kalanis\kw_templates\Template;
4
5
6
use kalanis\kw_templates\TemplateException;
7
8
9
/**
10
 * Trait TFile
11
 * @package kalanis\kw_templates\Template
12
 * Trait for loading templates from files, not from code
13
 */
14
trait TFile
15
{
16
17
    /**
18
     * @throws TemplateException
19
     * @return string
20
     */
21 2
    protected function loadTemplate(): string
22
    {
23 2
        $path = $this->templatePath();
24 2
        $result = @file_get_contents($path);
25 2
        if (false === $result) {
26 1
            throw new TemplateException(sprintf('Template file %s not found', $path));
27
        }
28 1
        return $result;
29
    }
30
31
    abstract protected function templatePath(): string;
32
}
33