| 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 |
||
| 60 | public function pageLookupCallBack(&$data) |
||
| 61 | { |
||
| 62 | // split out original parameters |
||
| 63 | $id = $data['id']; |
||
| 64 | $parsedQuery = (new QueryParser)->convert($id); |
||
| 65 | |||
| 66 | if (count($parsedQuery['ns']) > 0) { |
||
| 67 | $ns = cleanID($parsedQuery['ns'][0]) . ':'; |
||
| 68 | $id = implode(' ', $parsedQuery['highlight']); |
||
| 69 | } |
||
| 70 | |||
| 71 | $in_ns = $data['in_ns']; |
||
| 72 | $in_title = $data['in_title']; |
||
| 73 | $cleaned = cleanID($id); |
||
| 74 | |||
| 75 | $pages = array(); |
||
| 76 | if ($id !== '' && $cleaned !== '') { |
||
| 77 | $MetadataIndex = new MetadataIndex(); |
||
| 78 | $page_idx = $MetadataIndex->getPages(); |
||
| 79 | foreach ($page_idx as $p_id) { |
||
| 80 | if ((strpos($in_ns ? $p_id : noNSorNS($p_id), $cleaned) !== false)) { |
||
| 81 | if (!isset($pages[$p_id])) { |
||
| 82 | $pages[$p_id] = p_get_first_heading($p_id, METADATA_DONT_RENDER); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 | if ($in_title) { |
||
| 87 | $func = [$this, 'pageLookupTitleCompare']; |
||
| 88 | foreach ($MetadataIndex->lookupKey('title', $id, $func) as $p_id) { |
||
| 89 | if (!isset($pages[$p_id])) { |
||
| 90 | $pages[$p_id] = p_get_first_heading($p_id, METADATA_DONT_RENDER); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | if (isset($ns)) { |
||
| 97 | foreach (array_keys($pages) as $p_id) { |
||
| 98 | if (strpos($p_id, $ns) !== 0) { |
||
| 99 | unset($pages[$p_id]); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | // discard hidden pages |
||
| 105 | // discard nonexistent pages |
||
| 106 | // check ACL permissions |
||
| 107 | foreach (array_keys($pages) as $idx) { |
||
| 108 | if (!isVisiblePage($idx) || !page_exists($idx) || auth_quickaclcheck($idx) < AUTH_READ) { |
||
| 109 | unset($pages[$idx]); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | $pages = $this->filterResultsByTime($pages, $data['after'], $data['before']); |
||
| 114 | |||
| 115 | uksort($pages, [$this, 'pagesorter']); |
||
| 116 | return $pages; |
||
| 117 | } |
||
| 118 | |||
| 184 |