MustacheLoader::filenameFromIdent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Charcoal\View\Mustache;
6
7
// From Mustache
8
use Mustache_Loader as MustacheLoaderInterface;
9
10
// From 'charcoal-view'
11
use Charcoal\View\AbstractLoader;
12
use Charcoal\View\LoaderInterface;
13
14
/**
15
 * Mustache Template Loader
16
 *
17
 * Finds a Mustache template file in a collection of directory paths.
18
 */
19 View Code Duplication
class MustacheLoader extends AbstractLoader implements
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    LoaderInterface,
21
    MustacheLoaderInterface
22
{
23
    /**
24
     * Determine if the variable is a template literal.
25
     *
26
     * This method looks for any tag delimiters in the given string,
27
     * which a file path would most likely not have.
28
     *
29
     * @todo   Add support for custom delimiters.
30
     * @param  string $ident The template being evaluated.
31
     * @return boolean
32
     */
33
    protected function isTemplateString(string $ident): bool
34
    {
35
        return strpos($ident, '{{') !== false || parent::isTemplateString($ident);
36
    }
37
38
    /**
39
     * Convert an identifier to a file path.
40
     *
41
     * @param  string $ident The template identifier to convert to a filename.
42
     * @return string
43
     */
44
    protected function filenameFromIdent(string $ident): string
45
    {
46
        $filename  = str_replace([ '\\' ], '.', $ident);
47
        $filename .= '.mustache';
48
49
        return $filename;
50
    }
51
}
52