TemplateCompiler::compile()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 4
nc 4
nop 2
1
<?php
2
3
namespace Te7aHoudini\Laroute\Compilers;
4
5
class TemplateCompiler implements CompilerInterface
6
{
7
    /**
8
     * Compile a template with given data.
9
     *
10
     * @param $template
11
     * @param $data
12
     *
13
     * @return string
14
     */
15
    public function compile($template, $data)
16
    {
17
        foreach ($data as $key => $value) {
18
            $key = strtoupper($key);
19
20
            if (is_bool($value)) {
21
                $value = $value ? 'true' : 'false';
22
            }
23
24
            $template = preg_replace("#\\$$key\\$#i", $value, $template);
25
        }
26
27
        return $template;
28
    }
29
}
30