| Conditions | 20 |
| Paths | 3471 |
| Total Lines | 94 |
| 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 |
||
| 163 | $result = (new MetadataIndex($pid))->addMetaKeys($metadata); |
||
| 164 | if ($verbose) dbglog("Indexer: addMetaKeys({$page}) ".($result ? 'done' : 'failed')); |
||
| 165 | if (!$result) { |
||
| 166 | return false; |
||
| 167 | } |
||
| 168 | |||
| 169 | // Access to Fulltext Index |
||
| 170 | if ($indexenabled) { |
||
| 171 | $result = (new FulltextIndex($pid))->addWords($body); |
||
| 172 | if ($verbose) dbglog("Indexer: addWords() for {$page} done"); |
||
| 173 | if (!$result) { |
||
| 174 | return false; |
||
| 175 | } |
||
| 176 | } else { |
||
| 177 | if ($verbose) dbglog("Indexer: full text indexing disabled for {$page}"); |
||
| 178 | // ensure the page content deleted from the Fulltext index |
||
| 179 | $result = (new FulltextIndex($page))->deleteWords(); |
||
| 180 | if ($verbose) dbglog("Indexer: deleteWords() for {$page} done"); |
||
| 181 | if (!$result) { |
||
| 182 | return false; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | // update index tag file |
||
| 187 | io_saveFile($idxtag, $this->getVersion()); |
||
| 188 | if ($verbose) dbglog("Indexer: finished"); |
||
| 189 | |||
| 190 | return $result; |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Remove a page from the index |
||
| 195 | * |
||
| 196 | * Erases entries in all known indexes. Locking is handled internally. |
||
| 197 | * |
||
| 198 | * @param string $page name of the page to index |
||
| 199 | * @param bool $verbose print status messages |
||
| 200 | * @param bool $force force reindexing even when the index is up to date |
||
| 201 | * @return bool If the function completed successfully |
||
| 202 | * |
||
| 203 | * @throws IndexAccessException |
||
| 204 | * @throws IndexLockException |
||
| 205 | * @throws IndexWriteException |
||
| 206 | * @author Satoshi Sahara <[email protected]> |
||
| 207 | * @author Tom N Harris <[email protected]> |
||
| 208 | */ |
||
| 209 | public function deletePage($verbose = false, $force = false) |
||
| 210 | { |
||
| 211 | if (!isset($this->page)) { |
||
| 212 | throw new IndexAccessException('Indexer: invalid page name in deletePage'); |
||
| 213 | } else { |
||
| 214 | $page = $this->page; |
||
| 215 | } |
||
| 216 | |||
| 217 | $idxtag = metaFN($page,'.indexed'); |
||
| 218 | if (!$force && !file_exists($idxtag)) { |
||
| 219 | if ($verbose) dbglog("Indexer: {$page}.indexed file does not exist, ignoring"); |
||
| 220 | return true; |
||
| 221 | } |
||
| 222 | |||
| 223 | // retrieve pid from the page.idx file, $pid is always integer |
||
| 224 | $pid = $this->getPID($page); |
||
| 225 | |||
| 226 | // remove obsoleted content from Fulltext index |
||
| 227 | $result = (new FulltextIndex($pid))->deleteWords(); |
||
| 228 | if ($verbose) dbglog("Indexer: deleteWords() for {$page} done"); |
||
| 229 | if (!$result) { |
||
| 230 | return false; |
||
| 231 | } |
||
| 232 | |||
| 233 | // delete all keys of the page from metadata index |
||
| 234 | $result = (new MetadataIndex($pid))->deleteMetaKeys(); |
||
| 235 | if ($verbose) dbglog("Indexer: deleteMetaKeys() for {$page} done"); |
||
| 236 | if (!$result) { |
||
| 237 | return false; |
||
| 238 | } |
||
| 239 | |||
| 240 | // mark the page as deleted in the page.idx |
||
| 241 | $this->lock(); |
||
| 242 | $this->saveIndexKey('page', '', $pid, self::INDEX_MARK_DELETED.$page); |
||
| 243 | if ($verbose) dbglog("Indexer: {$page} has marked as deleted in page.idx"); |
||
| 244 | $this->unlock(); |
||
| 245 | |||
| 246 | unset(static::$pidCache[$pid]); |
||
| 247 | @unlink($idxtag); |
||
| 248 | return $result; |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Rename a page in the search index without changing the indexed content. |
||
| 253 | * This function doesn't check if the old or new name exists in the filesystem. |
||
| 254 | * It returns an error if the old page isn't in the page list of the indexer |
||
| 255 | * and it deletes all previously indexed content of the new page. |
||
| 256 | * |
||
| 257 | * @param string $oldpage The old page name |
||
| 319 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.