Code Duplication    Length = 31-33 lines in 2 locations

src/Charcoal/View/Mustache/MustacheLoader.php 1 location

@@ 19-51 (lines=33) @@
16
 *
17
 * Finds a Mustache template file in a collection of directory paths.
18
 */
19
class MustacheLoader extends AbstractLoader implements
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

src/Charcoal/View/Php/PhpLoader.php 1 location

@@ 16-46 (lines=31) @@
13
 *
14
 * Finds a PHP template file in a collection of directory paths.
15
 */
16
class PhpLoader extends AbstractLoader implements LoaderInterface
17
{
18
    /**
19
     * Determine if the variable is a template literal.
20
     *
21
     * This method looks for any PHP tags in the given string,
22
     * which a file path would most likely not have.
23
     *
24
     * @todo   Add support for custom delimiters.
25
     * @param  string $ident The template being evaluated.
26
     * @return boolean
27
     */
28
    protected function isTemplateString(string $ident): bool
29
    {
30
        return strpos($ident, '<?') !== false || parent::isTemplateString($ident);
31
    }
32
33
    /**
34
     * Convert an identifier to a file path.
35
     *
36
     * @param string $ident The identifier to convert.
37
     * @return string
38
     */
39
    protected function filenameFromIdent(string $ident): string
40
    {
41
        $filename = str_replace([ '\\' ], '.', $ident);
42
        $filename .= '.php';
43
44
        return $filename;
45
    }
46
}
47