Ajde_Template_Parser   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 82
Duplicated Lines 10.98 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 9
loc 82
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 4

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __isset() 0 6 1
A __get() 0 9 2
A __fallback() 9 9 2
A getHelper() 0 8 2
A getTemplate() 0 4 1
A parse() 0 4 1
A _getContents() 0 9 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
class Ajde_Template_Parser extends Ajde_Object_Standard
4
{
5
    /**
6
     * @var Ajde_Template
7
     */
8
    protected $_template = null;
9
10
    /**
11
     * @var Ajde_Template_Parser_Phtml_Helper
12
     */
13
    protected $_helper = null;
14
15
    /**
16
     * @param Ajde_Template $template
17
     */
18
    public function __construct(Ajde_Template $template)
19
    {
20
        $this->_template = $template;
21
    }
22
23
    public function __isset($name)
24
    {
25
        $template = $this->getTemplate();
26
27
        return $template->hasAssigned($name);
28
    }
29
30
    public function __get($name)
31
    {
32
        $template = $this->getTemplate();
33
        if ($template->hasAssigned($name)) {
34
            return $template->getAssigned($name);
35
        } else {
36
            throw new Ajde_Exception("No variable with name '".$name."' assigned to template.", 90019);
37
        }
38
    }
39
40 View Code Duplication
    public function __fallback($method, $arguments)
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...
41
    {
42
        $helper = $this->getHelper();
43
        if (method_exists($helper, $method)) {
44
            return call_user_func_array([$helper, $method], $arguments);
45
        } else {
46
            throw new Ajde_Exception('Call to undefined method '.get_class($this)."::$method()", 90006);
47
        }
48
    }
49
50
    /**
51
     * @return Ajde_Template_Parser_Phtml_Helper
52
     */
53
    public function getHelper()
54
    {
55
        if (!isset($this->_helper)) {
56
            $this->_helper = new Ajde_Template_Parser_Phtml_Helper($this);
57
        }
58
59
        return $this->_helper;
60
    }
61
62
    /**
63
     * @return Ajde_Template
64
     */
65
    public function getTemplate()
66
    {
67
        return $this->_template;
68
    }
69
70
    public function parse()
71
    {
72
        return $this->_getContents();
73
    }
74
75
    protected function _getContents()
76
    {
77
        ob_start();
78
        include $this->getTemplate()->getFilename();
79
        $contents = ob_get_contents();
80
        ob_end_clean();
81
82
        return $contents;
83
    }
84
}
85