Passed
Push — master ( b912aa...9d745d )
by Mathieu
01:50
created

MustacheLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 33
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isTemplateString() 4 4 2
A filenameFromIdent() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Charcoal\View\Mustache;
4
5
// From Mustache
6
use Mustache_Loader as MustacheLoaderInterface;
7
8
// From 'charcoal-view'
9
use Charcoal\View\AbstractLoader;
10
use Charcoal\View\LoaderInterface;
11
12
/**
13
 * Mustache Template Loader
14
 *
15
 * Finds a Mustache template file in a collection of directory paths.
16
 */
17 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...
18
    LoaderInterface,
19
    MustacheLoaderInterface
20
{
21
    /**
22
     * Determine if the variable is a template literal.
23
     *
24
     * This method looks for any tag delimiters in the given string,
25
     * which a file path would most likely not have.
26
     *
27
     * @todo   Add support for custom delimiters.
28
     * @param  string $ident The template being evaluated.
29
     * @return boolean
30
     */
31
    protected function isTemplateString($ident)
32
    {
33
        return strpos($ident, '{{') !== false || parent::isTemplateString($ident);
34
    }
35
36
    /**
37
     * Convert an identifier to a file path.
38
     *
39
     * @param  string $ident The template identifier to convert to a filename.
40
     * @return string
41
     */
42
    protected function filenameFromIdent($ident)
43
    {
44
        $filename  = str_replace([ '\\' ], '.', $ident);
45
        $filename .= '.mustache';
46
47
        return $filename;
48
    }
49
}
50