| Conditions | 11 |
| Paths | 300 |
| Total Lines | 52 |
| 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 |
||
| 126 | public function buildSelected() |
||
| 127 | { |
||
| 128 | //get the currentpage |
||
| 129 | $sel = array(); |
||
| 130 | // $queryString = $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : ''; |
||
| 131 | $queryString = XoopsRequest::getString('QUERY_STRING', '', 'SERVER') ? '?' |
||
| 132 | . XoopsRequest::getString('QUERY_STRING', |
||
| 133 | '', |
||
| 134 | 'SERVER') : ''; |
||
| 135 | // $self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $queryString; |
||
| 136 | $self = 'http://' . XoopsRequest::getString('HTTP_HOST', '', 'SERVER') . XoopsRequest::getString('PHP_SELF', '', |
||
| 137 | 'SERVER') |
||
| 138 | . $queryString; |
||
| 139 | |||
| 140 | //set a default page in case we don't get matches |
||
| 141 | $default = XOOPS_URL . '/index.php'; |
||
| 142 | |||
| 143 | //get all matching links |
||
| 144 | foreach ($this->output as $idx => $menu) { |
||
| 145 | $selected = 0; |
||
| 146 | if ($menu['link']) { |
||
| 147 | $selected = (false !== stristr($self, $menu['link'])) ? 1 : $selected; |
||
| 148 | } |
||
| 149 | $selected = ($menu['link'] == $self) ? 1 : $selected; |
||
| 150 | $selected = ($menu['link'] == $default) ? 1 : $selected; |
||
| 151 | if ($selected) { |
||
| 152 | $sel[$idx] = $menu; |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 156 | //From those links get only the longer one |
||
| 157 | $longlink = ''; |
||
| 158 | $longidx = 0; |
||
| 159 | foreach ($sel as $idx => $menu) { |
||
| 160 | if (strlen($menu['link']) > strlen($longlink)) { |
||
| 161 | $longidx = $idx; |
||
| 162 | $longlink = $menu['link']; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | /* |
||
| 167 | * When visiting site.com when XOOPS_URL is set to www.site.com |
||
| 168 | * longidx is not detected, this IF will prevent blank page |
||
| 169 | */ |
||
| 170 | if (isset($this->output[$longidx])) { |
||
| 171 | $this->output[$longidx]['selected'] = true; |
||
| 172 | $this->output[$longidx]['topselected'] = true; |
||
| 173 | |||
| 174 | //Now turn all this menu parents to selected |
||
| 175 | $this->addSelectedParents($this->output[$longidx]['pid']); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 204 |
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.