| Conditions | 14 |
| Paths | 20 |
| Total Lines | 51 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 24 | public function handleWidget() |
||
| 25 | { |
||
| 26 | $SQL_id = $this->owner->getRequest()->param('ID'); |
||
| 27 | if (!$SQL_id) { |
||
| 28 | return false; |
||
| 29 | } |
||
| 30 | |||
| 31 | // find WidgetArea relations |
||
| 32 | $widgetAreaRelations = array(); |
||
| 33 | $hasOnes = $this->owner->data()->hasOne(); |
||
| 34 | |||
| 35 | if (!$hasOnes) { |
||
| 36 | return false; |
||
| 37 | } |
||
| 38 | |||
| 39 | foreach ($hasOnes as $hasOneName => $hasOneClass) { |
||
| 40 | if ($hasOneClass == 'WidgetArea' || is_subclass_of($hasOneClass, 'WidgetArea')) { |
||
| 41 | $widgetAreaRelations[] = $hasOneName; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | // find widget |
||
| 46 | $widget = null; |
||
| 47 | $linked = null; |
||
| 48 | |||
| 49 | foreach ($widgetAreaRelations as $widgetAreaRelation) { |
||
| 50 | if ($widget) { |
||
| 51 | break; |
||
| 52 | } |
||
| 53 | |||
| 54 | $widget = $this->owner->data()->$widgetAreaRelation()->Widgets() |
||
| 55 | ->filter('ID', $SQL_id) |
||
| 56 | ->First(); |
||
| 57 | |||
| 58 | if(!$widget && ($this->owner->data()->$widgetAreaRelation() instanceof ElementalArea)) { |
||
| 59 | foreach($this->owner->data()->$widgetAreaRelation()->AllElements() as $element) { |
||
| 60 | if($element instanceof ElementVirtualLinked && $element->LinkedElementID == $SQL_id) { |
||
| 61 | $widget = $element->LinkedElement(); |
||
| 62 | |||
| 63 | break; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | if (!$widget) { |
||
| 70 | return; |
||
| 71 | } |
||
| 72 | |||
| 73 | return $widget->getController(); |
||
| 74 | } |
||
| 75 | } |
||
| 76 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.