Ajde_Template_Parser::__fallback()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
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