| Conditions | 5 |
| Paths | 5 |
| Total Lines | 52 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 32 | public function Menu() |
||
| 33 | { |
||
| 34 | $menu = new ArrayList(); |
||
| 35 | |||
| 36 | $menuEntries = array( |
||
| 37 | //array('controller' => 'HomeController'), |
||
| 38 | array('controller' => 'AddonsController'), |
||
| 39 | array( |
||
| 40 | 'link' => Controller::join_links( |
||
| 41 | singleton('AddonsController')->Link(), |
||
| 42 | '?type=theme&view=expanded' |
||
| 43 | ), |
||
| 44 | 'title' => 'Themes', |
||
| 45 | ), |
||
| 46 | array('controller' => 'VendorsController'), |
||
| 47 | array('controller' => 'AuthorsController'), |
||
| 48 | array('controller' => 'TagsController'), |
||
| 49 | array('controller' => 'SubmitAddonController'), |
||
| 50 | ); |
||
| 51 | |||
| 52 | foreach ($menuEntries as $menuEntry) { |
||
| 53 | if(isset($menuEntry['controller'])) { |
||
| 54 | $inst = singleton($menuEntry['controller']); |
||
| 55 | $active = false; |
||
| 56 | |||
| 57 | foreach (self::$controller_stack as $candidate) { |
||
| 58 | $active = ( |
||
| 59 | $candidate instanceof $menuEntry['controller'] |
||
| 60 | && $this->request->getVar('type') != 'theme' |
||
| 61 | ); |
||
| 62 | } |
||
| 63 | |||
| 64 | $menu->push(new ArrayData(array( |
||
| 65 | 'Title' => $inst->Title(), |
||
| 66 | 'Link' => $inst->Link(), |
||
| 67 | 'Active' => $active, |
||
| 68 | 'MenuItemType' => $inst->MenuItemType() |
||
| 69 | ))); |
||
| 70 | } else { |
||
| 71 | $active = ($this->request->getVar('type') == 'theme'); |
||
| 72 | $menu->push(new ArrayData(array( |
||
| 73 | 'Title' => $menuEntry['title'], |
||
| 74 | 'Link' => $menuEntry['link'], |
||
| 75 | 'Active' => $active, |
||
| 76 | 'MenuItemType' => 'link', |
||
| 77 | ))); |
||
| 78 | } |
||
| 79 | |||
| 80 | } |
||
| 81 | |||
| 82 | return $menu; |
||
| 83 | } |
||
| 84 | |||
| 108 |