Completed
Push — master ( 74371a...6da8c0 )
by Vladimir
02:21
created

TwigTextProfiler::formatTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Templating\Twig;
9
10
use Twig_Profiler_Dumper_Text;
11
use Twig_Profiler_Profile;
12
13
class TwigTextProfiler extends Twig_Profiler_Dumper_Text
14
{
15
    private $templateMappings;
16
17
    /**
18
     * @param string[] $templateMappings
19
     */
20
    public function setTemplateMappings($templateMappings)
21
    {
22
        $this->templateMappings = $templateMappings;
23
    }
24
25
    protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix)
26
    {
27
        return sprintf('%sā”” %s', $prefix, $this->getMappedTemplateName($profile));
28
    }
29
30
    protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix)
31
    {
32
        return sprintf('%sā”” %s::%s(%s)', $prefix, $this->getMappedTemplateName($profile), $profile->getType(), $profile->getName());
33
    }
34
35
    private function getMappedTemplateName(Twig_Profiler_Profile $profile)
36
    {
37
        $name = $profile->getTemplate();
38
39
        return isset($this->templateMappings[$name]) ? $this->templateMappings[$name] : $profile->getTemplate();
40
    }
41
}
42