| Conditions | 11 |
| Paths | 43 |
| Total Lines | 77 |
| Code Lines | 22 |
| Lines | 10 |
| Ratio | 12.99 % |
| Changes | 2 | ||
| 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 module is shorthand |
||
| 200 | * then check to see if we have |
||
| 201 | * an active module to use for it. |
||
| 202 | */ |
||
| 203 | if ($namespace === 'module' && $this->module) { |
||
| 204 | $namespace = $this->module->getNamespace(); |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * If the view is already in |
||
| 209 | * the theme then skip it. |
||
| 210 | */ |
||
| 211 | if ($namespace == 'theme' || str_is('*.theme.*', $namespace)) { |
||
| 212 | return null; |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * If the view is a streams view then |
||
| 217 | * it's real easy to guess what the |
||
| 218 | * override path should be. |
||
| 219 | */ |
||
| 220 | if ($namespace == 'streams') { |
||
| 221 | $path = $this->theme->getNamespace('streams/' . $path); |
||
| 222 | } |
||
| 223 | |||
| 224 | /** |
||
| 225 | * If the view uses a dot syntax namespace then |
||
| 226 | * transform it all into the override view path. |
||
| 227 | */ |
||
| 228 | View Code Duplication | if ($addon = $this->addons->get($namespace)) { |
|
| 229 | $path = $this->theme->getNamespace( |
||
| 230 | "addons/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/" . $path |
||
| 231 | ); |
||
| 232 | } |
||
| 233 | |||
| 234 | if ($this->view->exists($path)) { |
||
| 235 | return $path; |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * If the view uses a dot syntax namespace then |
||
| 240 | * transform it all into the override view path. |
||
| 241 | * |
||
| 242 | * @deprecated since v3.0.0 |
||
| 243 | */ |
||
| 244 | View Code Duplication | if ($addon) { |
|
| 245 | $path = $this->theme->getNamespace( |
||
| 246 | "addon/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/" . $path |
||
| 247 | ); |
||
| 248 | } |
||
| 249 | |||
| 250 | if ($this->view->exists($path)) { |
||
| 251 | return $path; |
||
| 252 | } |
||
| 253 | |||
| 254 | return null; |
||
| 255 | } |
||
| 256 | } |
||
| 257 |
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.