Completed
Branch master (e379bd)
by Pierre-Henry
33:06
created

Smarty_Template_Source::render()   B

Complexity

Conditions 7
Paths 9

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 10
nc 9
nop 1
dl 0
loc 16
rs 8.2222
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Smarty_Template_Source::getTimeStamp() 0 7 2
1
<?php
2
3
/**
4
 * Smarty Resource Data Object
5
 * Meta Data Container for Template Files
6
 *
7
 * @package    Smarty
8
 * @subpackage TemplateResources
9
 * @author     Rodney Rehm
10
 *
11
 */
12
class Smarty_Template_Source
13
{
14
    /**
15
     * Unique Template ID
16
     *
17
     * @var string
18
     */
19
    public $uid = null;
20
21
    /**
22
     * Template Resource (Smarty_Internal_Template::$template_resource)
23
     *
24
     * @var string
25
     */
26
    public $resource = null;
27
28
    /**
29
     * Resource Type
30
     *
31
     * @var string
32
     */
33
    public $type = null;
34
35
    /**
36
     * Resource Name
37
     *
38
     * @var string
39
     */
40
    public $name = null;
41
42
    /**
43
     * Source Filepath
44
     *
45
     * @var string
46
     */
47
    public $filepath = null;
48
49
    /**
50
     * Source Timestamp
51
     *
52
     * @var integer
53
     */
54
    public $timestamp = null;
55
56
    /**
57
     * Source Existence
58
     *
59
     * @var boolean
60
     */
61
    public $exists = false;
62
63
    /**
64
     * Source File Base name
65
     *
66
     * @var string
67
     */
68
    public $basename = null;
69
70
    /**
71
     * The Components an extended template is made of
72
     *
73
     * @var \Smarty_Template_Source[]
74
     */
75
    public $components = null;
76
77
    /**
78
     * Resource Handler
79
     *
80
     * @var \Smarty_Resource
81
     */
82
    public $handler = null;
83
84
    /**
85
     * Smarty instance
86
     *
87
     * @var Smarty
88
     */
89
    public $smarty = null;
90
91
    /**
92
     * Resource is source
93
     *
94
     * @var bool
95
     */
96
    public $isConfig = false;
97
98
    /**
99
     * Template source content eventually set by default handler
100
     *
101
     * @var string
102
     */
103
    public $content = null;
104
105
    /**
106
     * Name of the Class to compile this resource's contents with
107
     *
108
     * @var string
109
     */
110
    public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
111
112
    /**
113
     * Name of the Class to tokenize this resource's contents with
114
     *
115
     * @var string
116
     */
117
    public $template_lexer_class = 'Smarty_Internal_Templatelexer';
118
119
    /**
120
     * Name of the Class to parse this resource's contents with
121
     *
122
     * @var string
123
     */
124
    public $template_parser_class = 'Smarty_Internal_Templateparser';
125
126
    /**
127
     * create Source Object container
128
     *
129
     * @param Smarty_Resource $handler  Resource Handler this source object communicates with
0 ignored issues
show
Bug introduced by
There is no parameter named $handler. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
130
     * @param Smarty          $smarty   Smarty instance this source object belongs to
131
     * @param string          $resource full template_resource
132
     * @param string          $type     type of resource
133
     * @param string          $name     resource name
134
     *
135
     */
136
    public function __construct(Smarty $smarty, $resource, $type, $name)
137
    {
138
        $this->handler =
139
            isset($smarty->_cache[ 'resource_handlers' ][ $type ]) ? $smarty->_cache[ 'resource_handlers' ][ $type ] :
140
                Smarty_Resource::load($smarty, $type);
141
        $this->smarty = $smarty;
142
        $this->resource = $resource;
143
        $this->type = $type;
144
        $this->name = $name;
145
    }
146
147
    /**
148
     * initialize Source Object for given resource
149
     * Either [$_template] or [$smarty, $template_resource] must be specified
150
     *
151
     * @param  Smarty_Internal_Template $_template         template object
152
     * @param  Smarty                   $smarty            smarty object
153
     * @param  string                   $template_resource resource identifier
154
     *
155
     * @return Smarty_Template_Source Source Object
156
     * @throws SmartyException
157
     */
158
    public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
159
                                $template_resource = null)
160
    {
161
        if ($_template) {
162
            $smarty = $_template->smarty;
163
            $template_resource = $_template->template_resource;
164
        }
165
        if (empty($template_resource)) {
166
            throw new SmartyException('Source: Missing  name');
167
        }
168
        // parse resource_name, load resource handler, identify unique resource name
169
        if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
170
            $type = $match[ 1 ];
171
            $name = $match[ 2 ];
172
        } else {
173
            // no resource given, use default
174
            // or single character before the colon is not a resource type, but part of the filepath
175
            $type = $smarty->default_resource_type;
176
            $name = $template_resource;
177
        }
178
        // create new source  object
179
        $source = new Smarty_Template_Source($smarty, $template_resource, $type, $name);
0 ignored issues
show
Bug introduced by
It seems like $smarty defined by parameter $smarty on line 158 can be null; however, Smarty_Template_Source::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
180
        $source->handler->populate($source, $_template);
181
        if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
182
            Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
183
            $source->handler->populate($source, $_template);
184
        }
185
        return $source;
186
    }
187
188
    /**
189
     * Get source time stamp
190
     *
191
     * @return int
192
     */
193
    public function getTimeStamp()
194
    {
195
        if (!isset($this->timestamp)) {
196
            $this->handler->populateTimestamp($this);
197
        }
198
        return $this->timestamp;
199
    }
200
201
    /**
202
     * Get source content
203
     *
204
     * @return string
205
     */
206
    public function getContent()
207
    {
208
        return isset($this->content) ? $this->content : $this->handler->getContent($this);
209
    }
210
}
211