Template   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildTop() 0 8 2
A buildBottom() 0 8 2
A split() 0 11 2
A doSplit() 0 5 1
1
<?php
2
namespace Potherca\Apache\Modules\AutoIndex;
3
4
use PHPTAL;
5
6
class Template implements TemplateInterface
7
{
8
    const DELIMINATOR = '<!-- ┈✂┈┈┈┈┈✄┈┈┈┈┈✄┈┈┈┈┈✄┈┈┈┈┈✄┈┈┈┈┈✄┈┈┈┈┈✂┈┈┈┈┈✄┈┈┈┈┈✂┈┈┈┈┈✄┈┈┈┈┈✂┈┈┈┈┈✄┈ -->';
9
10
    /** @var string */
11
    private $bottom;
12
    /** @var string */
13
    private $top;
14
    /** @var array */
15
    private $context = [
16
        'sIndexHtml' => '',
17
        'sIndex' => '',
18
        'sSignature' => '',
19
        'sReadmeHtml' => '',
20
        'aPreviews' => [],
21
        'sFooterReadme' => '',
22
        'aCssAssets' => [],
23
        'aJsAssets' => [],
24
    ];
25
26
    /** @var PHPTAL */
27
    private $template;
28
29
    final public function __construct(PHPTAL $template)
30
    {
31
        $this->template = $template;
32
    }
33
34
    final public function buildTop(array $context)
35
    {
36
        if (empty($this->top)) {
37
            $this->doSplit($context);
38
        }
39
40
        return $this->top;
41
    }
42
43
    final public function buildBottom(array $context)
44
    {
45
        if (empty($this->bottom)) {
46
            $this->doSplit($context);
47
        }
48
49
        return $this->bottom;
50
    }
51
52
    private function split(PHPTAL $template, array $context)
53
    {
54
        foreach ($context as $key => $value) {
55
            $template->set($key, $value);
56
        }
57
58
        $sHtml = $template->execute();
59
60
        list($this->top, $middle, $this->bottom) = explode(self::DELIMINATOR, $sHtml);
61
        unset($middle);
62
    }
63
64
    /**
65
     * @param $context
66
     */
67
    private function doSplit(array $context)
68
    {
69
        $context = array_merge($this->context, $context);
70
        $this->split($this->template, $context);
71
    }
72
}
73
74
/*EOF*/
75