Mustache   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 13.95 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getMustacheTest() 0 4 1
A getMustacheTest2() 0 4 1
B getMustache() 0 24 1
A getMustacheview() 0 13 1
A getMustachelayout() 12 12 1
A getIndex() 0 6 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
 * Mustache Controller
4
 * Some test routes for mustache
5
 * This is only for testing Mustache
6
 *
7
 * @category    app
8
 * @package     controllers
9
 * @copyright   Copyright (c) 2016, Arroyo Labs, www.arroyolabs.com
10
 * @author      John Arroyo, [email protected]
11
 */
12
namespace app\controllers;
13
14
15
/**
16
 * Example Controller Class
17
 */
18
class Mustache extends \erdiko\core\Controller
19
{
20
    public function getMustacheTest($name)
21
    {
22
        return "[[{$name}]]";
23
    }
24
25
    public function getMustacheTest2()
26
    {
27
        return $this->getView('examples/one');
28
    }
29
30
    /** 
31
     * Example playing with mustache templates
32
     * the $string variable would really be a view, but it's good to see here.
33
     */
34
    public function getMustache()
35
    {
36
        $string = "Hello, {{ planet }}!
37
            {{# get_region }}two{{/ get_region }}
38
            {{# get_region }}'three'{{/ get_region }}
39
            {{# index }}four{{/ index }}
40
            {{# getMustacheTest2 }}five{{/ getMustacheTest2 }}
41
            ";
42
43
        $m = new \Mustache_Engine;
44
        $data = array(
45
            'planet' => 'world',
46
            'get_region' => function($name) { 
47
                return $this->getMustacheTest($name); 
48
                },
49
            'index' => function() {
50
                return $this->getMustacheTest2();
51
                }
52
            );
53
        $content = $m->render($string, $data);
54
55
        $this->setTitle('Mustache');
56
        $this->setContent($content);
57
    }
58
59
    /** 
60
     * Example playing with mustache templates
61
     * the $string variable would really be a view, but it's good to see here.
62
     */
63
    public function getMustacheview()
64
    {
65
        // Send data and attach a function to mustache
66
        $data = array(
67
            'planet' => 'world',
68
            'get_region' => function($name) { 
69
                return $this->getMustacheTest($name); 
70
                }
71
            );
72
73
        $this->setTitle('Mustache View');
74
        $this->addView('examples/mustache', $data);
75
    }
76
77
    /** 
78
     * Example playing with mustache templates
79
     * the $string variable would really be a view, but it's good to see here.
80
     */
81 View Code Duplication
    public function getMustachelayout()
0 ignored issues
show
Duplication introduced by
This method 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...
82
    {
83
        // You can add other views (containers) or text
84
        $columns = array(
85
            'one' => new \erdiko\core\View('examples/one'),
86
            'two' => $this->getView('examples/two') . $this->getView('examples/three')
87
            );
88
        
89
        $this->setContent($this->getLayout('mustache/2column-mustache', $columns));
90
91
        $this->setTitle('Mustache Template');
92
    }
93
94
    /**
95
     * Homepage Action (index)
96
     */
97
    public function getIndex()
98
    {
99
        // Add page data
100
        $this->setTitle('Examples');
101
        $this->addView('examples/examples');
102
    }
103
}
104