BraceParser::parse()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 13
rs 10
1
<?php
2
3
namespace Maestriam\FileSystem\Foundation\Template;
4
5
abstract class BraceParser
6
{
7
    /**
8
     * Substitui as lacunas de um template pelo seu real conteúdo
9
     *
10
     * @param string $content
11
     * @param array $placeholders
12
     * @return string
13
     */
14
    static public function parse(string $content, array $placeholders = []) : string
15
    {
16
        foreach ($placeholders as $placeholder => $word) {
17
18
            if (is_array($placeholder) || is_array($word)) {
19
                throw new \Exception();                
20
            }
21
22
            $search  = sprintf('{{%s}}', $placeholder);
23
            $content = str_replace($search, $word, $content);                        
24
        }
25
26
        return $content;
27
    }
28
}