Completed
Push — master ( 9da0fd...2ae4f2 )
by Tomáš
9s
created

DynamicStringLoader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 53
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addTemplate() 0 4 1
A getReferredName() 0 5 1
A getUniqueId() 0 5 1
A getContent() 0 10 2
A isExpired() 0 5 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
14
/**
15
 * Inspired by @see \Latte\Loaders\StringLoader.
16
 */
17
final class DynamicStringLoader implements ILoader
18
{
19
    /**
20
     * @var array [name => content]
21
     */
22
    private $templates = [];
23
24 6
    public function addTemplate(string $name, string $content)
25
    {
26 6
        $this->templates[$name] = $content;
27 6
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 5
    public function getContent($name) : string
33
    {
34 5
        if (isset($this->templates[$name])) {
35 4
            return $this->templates[$name];
36
        }
37
38 1
        throw new \RuntimeException(
39 1
            sprintf('Missing template "%s".', $name)
40
        );
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function isExpired($name, $time) : bool
47
    {
48
        // needed?
49 1
        return false;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 2
    public function getReferredName($name, $referringName) : string
56
    {
57
        // needed?
58 2
        return $name;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 4
    public function getUniqueId($name)
65
    {
66
        // needed?
67 4
        return $this->getContent($name);
68
    }
69
}
70