| Conditions | 18 |
| Paths | 48 |
| Total Lines | 58 |
| 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 |
||
| 81 | public function pageLookupCallBack(&$data) |
||
| 82 | { |
||
| 83 | // split out original parameters |
||
| 84 | $id = $data['id']; |
||
| 85 | $parsedQuery = (new QueryParser)->convert($id); |
||
| 86 | |||
| 87 | if (count($parsedQuery['ns']) > 0) { |
||
| 88 | $ns = cleanID($parsedQuery['ns'][0]) . ':'; |
||
| 89 | $id = implode(' ', $parsedQuery['highlight']); |
||
| 90 | } |
||
| 91 | |||
| 92 | $in_ns = $data['in_ns']; |
||
| 93 | $in_title = $data['in_title']; |
||
| 94 | $cleaned = cleanID($id); |
||
| 95 | |||
| 96 | $pages = array(); |
||
| 97 | if ($id !== '' && $cleaned !== '') { |
||
| 98 | $MetadataIndex = MetadataIndex::getInstance(); |
||
| 99 | $page_idx = $MetadataIndex->getPages(); |
||
| 100 | foreach ($page_idx as $p_id) { |
||
| 101 | if ((strpos($in_ns ? $p_id : noNSorNS($p_id), $cleaned) !== false)) { |
||
| 102 | if (!isset($pages[$p_id])) { |
||
| 103 | $pages[$p_id] = p_get_first_heading($p_id, METADATA_DONT_RENDER); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | if ($in_title) { |
||
| 108 | $func = [$this, 'pageLookupTitleCompare']; |
||
| 109 | foreach ($MetadataIndex->lookupKey('title', $id, $func) as $p_id) { |
||
| 110 | if (!isset($pages[$p_id])) { |
||
| 111 | $pages[$p_id] = p_get_first_heading($p_id, METADATA_DONT_RENDER); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | if (isset($ns)) { |
||
| 118 | foreach (array_keys($pages) as $p_id) { |
||
| 119 | if (strpos($p_id, $ns) !== 0) { |
||
| 120 | unset($pages[$p_id]); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | // discard hidden pages |
||
| 126 | // discard nonexistent pages |
||
| 127 | // check ACL permissions |
||
| 128 | foreach (array_keys($pages) as $idx) { |
||
| 129 | if (!isVisiblePage($idx) || !page_exists($idx) || auth_quickaclcheck($idx) < AUTH_READ) { |
||
| 130 | unset($pages[$idx]); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | $pages = $this->filterResultsByTime($pages, $data['after'], $data['before']); |
||
| 135 | |||
| 136 | uksort($pages, [$this, 'pagesorter']); |
||
| 137 | return $pages; |
||
| 138 | } |
||
| 139 | |||
| 205 |