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