| Conditions | 11 |
| Paths | 9 |
| Total Lines | 47 |
| Code Lines | 28 |
| 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 |
||
| 103 | |||
| 104 | $matches = array(); |
||
| 105 | preg_match('/remove|add/', $request->getURL(), $matches); |
||
| 106 | |||
| 107 | $action = new AddToshortlistAction(); |
||
| 108 | |||
| 109 | if ($matches[0] == 'remove') { |
||
| 110 | $action = new RemoveFromshortlistAction(); |
||
| 111 | } |
||
| 112 | |||
| 113 | $status = $action->performAction( |
||
| 114 | $shortlist = $this->getSessionShortList(), |
||
| 115 | $ID = $request->getVar('id'), |
||
| 116 | $type = $request->getVar('type'), |
||
| 117 | $session = $request->getVar('s') |
||
| 118 | ); |
||
| 119 | |||
| 120 | if ($request->isAjax()) { |
||
| 121 | $shortlist = $this->getSessionShortList(); |
||
| 122 | $url = false; |
||
| 123 | |||
| 124 | if ($shortlist && $shortlist->exists()) { |
||
| 125 | $url = $shortlist->Link(); |
||
| 126 | } |
||
| 127 | |||
| 128 | return json_encode(array( |
||
| 129 | 'count' => $this->shortListCount($session), |
||
| 130 | 'url' => $url |
||
| 131 | )); |
||
| 132 | } |
||
| 133 | |||
| 134 | if (array_key_exists('output', $request->getVars())) { |
||
| 135 | return $status; |
||
| 136 | } |
||
| 137 | |||
| 138 | return $this->redirectBack(); |
||
| 139 | } |
||
| 140 | |||
| 141 | |||
| 142 | /** |
||
| 143 | * Get the number of items in the current short list. |
||
| 144 | * |
||
| 145 | * @param session The session to check & find a shortlist for. |
||
| 146 | * @return mixed false if no session exists - else the number of items in the shortlist. |
||
| 147 | * */ |
||
| 148 | public function shortListCount($session = false) |
||
| 149 | { |
||
| 150 | if (is_null(self::getSecurityToken()) || !$session || $session != self::getSecurityToken()) { |
||
| 201 |