Conditions | 9 |
Paths | 22 |
Total Lines | 68 |
Code Lines | 20 |
Lines | 10 |
Ratio | 14.71 % |
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 namespace Anomaly\Streams\Platform\View; |
||
179 | public function getOverloadPath(View $view) |
||
180 | { |
||
181 | |||
182 | /** |
||
183 | * We can only overload namespaced |
||
184 | * views right now. |
||
185 | */ |
||
186 | if (!str_contains($view->getName(), '::')) { |
||
187 | return null; |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * Split the view into it's |
||
192 | * namespace and path. |
||
193 | */ |
||
194 | list($namespace, $path) = explode('::', $view->getName()); |
||
195 | |||
196 | $path = str_replace('.', '/', $path); |
||
197 | |||
198 | /** |
||
199 | * If the view is already in |
||
200 | * the theme then skip it. |
||
201 | */ |
||
202 | if ($namespace == 'theme' || str_is('*.theme.*', $namespace)) { |
||
203 | return null; |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * If the view is a streams view then |
||
208 | * it's real easy to guess what the |
||
209 | * override path should be. |
||
210 | */ |
||
211 | if ($namespace == 'streams') { |
||
212 | $path = $this->theme->getNamespace('streams/' . $path); |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * If the view uses a dot syntax namespace then |
||
217 | * transform it all into the override view path. |
||
218 | */ |
||
219 | View Code Duplication | if ($addon = $this->addons->get($namespace)) { |
|
220 | $path = $this->theme->getNamespace( |
||
221 | "addons/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/" . $path |
||
222 | ); |
||
223 | } |
||
224 | |||
225 | if ($this->view->exists($path)) { |
||
226 | return $path; |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * If the view uses a dot syntax namespace then |
||
231 | * transform it all into the override view path. |
||
232 | * |
||
233 | * @deprecated since v3.0.0 |
||
234 | */ |
||
235 | View Code Duplication | if ($addon) { |
|
236 | $path = $this->theme->getNamespace( |
||
237 | "addon/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/" . $path |
||
238 | ); |
||
239 | } |
||
240 | |||
241 | if ($this->view->exists($path)) { |
||
242 | return $path; |
||
243 | } |
||
244 | |||
245 | return null; |
||
246 | } |
||
247 | } |
||
248 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.