Conditions | 30 |
Paths | 1115 |
Total Lines | 69 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
154 | public function isCached(Smarty_Internal_Template $_template) |
||
155 | { |
||
156 | if ($this->valid !== null) { |
||
157 | return $this->valid; |
||
158 | } |
||
159 | while (true) { |
||
160 | while (true) { |
||
161 | if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) { |
||
162 | $this->valid = false; |
||
163 | } else { |
||
164 | $this->valid = true; |
||
165 | } |
||
166 | if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_CURRENT |
||
167 | && $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime) |
||
168 | ) { |
||
169 | // lifetime expired |
||
170 | $this->valid = false; |
||
171 | } |
||
172 | if ($this->valid && $_template->compile_check === Smarty::COMPILECHECK_ON |
||
173 | && $_template->source->getTimeStamp() > $this->timestamp |
||
174 | ) { |
||
175 | $this->valid = false; |
||
176 | } |
||
177 | if ($this->valid || !$_template->smarty->cache_locking) { |
||
178 | break; |
||
179 | } |
||
180 | if (!$this->handler->locked($_template->smarty, $this)) { |
||
|
|||
181 | $this->handler->acquireLock($_template->smarty, $this); |
||
182 | break 2; |
||
183 | } |
||
184 | $this->handler->populate($this, $_template); |
||
185 | } |
||
186 | if ($this->valid) { |
||
187 | if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) { |
||
188 | // load cache file for the following checks |
||
189 | if ($_template->smarty->debugging) { |
||
190 | $_template->smarty->_debug->start_cache($_template); |
||
191 | } |
||
192 | if ($this->handler->process($_template, $this) === false) { |
||
193 | $this->valid = false; |
||
194 | } else { |
||
195 | $this->processed = true; |
||
196 | } |
||
197 | if ($_template->smarty->debugging) { |
||
198 | $_template->smarty->_debug->end_cache($_template); |
||
199 | } |
||
200 | } else { |
||
201 | $this->is_locked = true; |
||
202 | continue; |
||
203 | } |
||
204 | } else { |
||
205 | return $this->valid; |
||
206 | } |
||
207 | if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED |
||
208 | && $_template->cached->cache_lifetime >= 0 |
||
209 | && (time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime)) |
||
210 | ) { |
||
211 | $this->valid = false; |
||
212 | } |
||
213 | if ($_template->smarty->cache_locking) { |
||
214 | if (!$this->valid) { |
||
215 | $this->handler->acquireLock($_template->smarty, $this); |
||
216 | } elseif ($this->is_locked) { |
||
217 | $this->handler->releaseLock($_template->smarty, $this); |
||
218 | } |
||
219 | } |
||
220 | return $this->valid; |
||
221 | } |
||
222 | return $this->valid; |
||
223 | } |
||
258 |
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.