Conditions | 13 |
Paths | 177 |
Total Lines | 86 |
Code Lines | 27 |
Lines | 10 |
Ratio | 11.63 % |
Changes | 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; |
||
169 | public function getOverloadPath(View $view) |
||
170 | { |
||
171 | |||
172 | /* |
||
173 | * We can only overload namespaced |
||
174 | * views right now. |
||
175 | */ |
||
176 | if (!str_contains($view->getName(), '::')) { |
||
177 | return null; |
||
178 | } |
||
179 | |||
180 | /* |
||
181 | * Split the view into it's |
||
182 | * namespace and path. |
||
183 | */ |
||
184 | list($namespace, $path) = explode('::', $view->getName()); |
||
185 | |||
186 | $override = null; |
||
187 | |||
188 | $path = str_replace('.', '/', $path); |
||
189 | |||
190 | /* |
||
191 | * If the namespace is shorthand |
||
192 | * then check to see if we have |
||
193 | * an active addon to use for it. |
||
194 | */ |
||
195 | if ($namespace === 'module' && $this->module) { |
||
196 | $namespace = $this->module->getNamespace(); |
||
197 | } |
||
198 | |||
199 | if ($namespace === 'theme' && $this->theme) { |
||
200 | $namespace = $this->theme->getNamespace(); |
||
201 | } |
||
202 | |||
203 | /* |
||
204 | * If the view is a streams view then |
||
205 | * it's real easy to guess what the |
||
206 | * override path should be. |
||
207 | */ |
||
208 | if ($namespace == 'streams') { |
||
209 | $path = $this->theme->getNamespace('streams/' . $path); |
||
210 | } |
||
211 | |||
212 | /* |
||
213 | * If the view uses a dot syntax namespace then |
||
214 | * transform it all into the override view path. |
||
215 | */ |
||
216 | View Code Duplication | if ($addon = $this->addons->get($namespace)) { |
|
217 | $override = $this->theme->getNamespace( |
||
218 | "addons/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/" . $path |
||
219 | ); |
||
220 | } |
||
221 | |||
222 | if ($this->view->exists($override)) { |
||
223 | return $override; |
||
224 | } |
||
225 | |||
226 | /** |
||
227 | * Check if a published override exists. |
||
228 | */ |
||
229 | if ($addon) { |
||
230 | $override = "app::addons/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/views/" . $path; |
||
231 | } |
||
232 | |||
233 | if ($this->view->exists($override)) { |
||
234 | return $override; |
||
235 | } |
||
236 | |||
237 | /* |
||
238 | * If the view uses a dot syntax namespace then |
||
239 | * transform it all into the override view path. |
||
240 | * |
||
241 | * @deprecated since v3.0.0 |
||
242 | */ |
||
243 | View Code Duplication | if ($addon) { |
|
244 | $override = $this->theme->getNamespace( |
||
245 | "addon/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/" . $path |
||
246 | ); |
||
247 | } |
||
248 | |||
249 | if ($this->view->exists($override)) { |
||
250 | return $override; |
||
251 | } |
||
252 | |||
253 | return null; |
||
254 | } |
||
255 | |||
299 |