DynamicStringLoader::isExpired()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Renderable\Latte;
11
12
use Latte\ILoader;
13
use RuntimeException;
14
15
/**
16
 * Inspired by @see \Latte\Loaders\StringLoader.
17
 */
18
final class DynamicStringLoader implements ILoader
19
{
20
    /**
21
     * @var array [name => content]
22
     */
23
    private $templates = [];
24
25 7
    public function addTemplate(string $name, string $content)
26
    {
27 7
        $this->templates[$name] = $content;
28 7
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 6
    public function getContent($name) : string
34
    {
35 6
        if (isset($this->templates[$name])) {
36 5
            return $this->templates[$name];
37
        }
38
39 1
        throw new RuntimeException(
40 1
            sprintf('Missing template "%s".', $name)
41
        );
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 1
    public function isExpired($name, $time) : bool
48
    {
49
        // needed?
50 1
        return false;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 1
    public function getReferredName($name, $referringName) : string
57
    {
58
        // needed?
59 1
        return $name;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 5
    public function getUniqueId($name)
66
    {
67
        // needed?
68 5
        return $this->getContent($name);
69
    }
70
}
71