From 42ea7f447f39fbc2f79eaaec31f8c10ede59c5d0 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 11:30:27 +0200 Subject: Many PHPDocs, some unused and dyn declared vars many PHPDocs some unused variables some dynamically declared variables declared --- inc/indexer.php | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 6 deletions(-) (limited to 'inc/indexer.php') diff --git a/inc/indexer.php b/inc/indexer.php index 5ca2f0bb1..ec0c523e0 100644 --- a/inc/indexer.php +++ b/inc/indexer.php @@ -61,6 +61,8 @@ define('IDX_ASIAN', '(?:'.IDX_ASIAN1.'|'.IDX_ASIAN2.'|'.IDX_ASIAN3.')'); * * @author Tom N Harris * @author Michael Hamann + * + * @return int|string */ function idx_get_version(){ static $indexer_version = null; @@ -84,6 +86,9 @@ function idx_get_version(){ * Differs from strlen in handling of asian characters. * * @author Tom N Harris + * + * @param string $w + * @return int */ function wordlen($w){ $l = strlen($w); @@ -115,7 +120,8 @@ class Doku_Indexer { * * @param string $page a page name * @param string $text the body of the page - * @return boolean the function completed successfully + * @return string|boolean the function completed successfully + * * @author Tom N Harris * @author Andreas Gohr */ @@ -190,6 +196,7 @@ class Doku_Indexer { * * @param string $text content of the page * @return array list of word IDs and number of times used + * * @author Andreas Gohr * @author Christopher Smith * @author Tom N Harris @@ -245,7 +252,8 @@ class Doku_Indexer { * @param string $page a page name * @param mixed $key a key string or array of key=>value pairs * @param mixed $value the value or list of values - * @return boolean the function completed successfully + * @return boolean|string the function completed successfully + * * @author Tom N Harris * @author Michael Hamann */ @@ -453,7 +461,8 @@ class Doku_Indexer { * Erases entries in all known indexes. * * @param string $page a page name - * @return boolean the function completed successfully + * @return string|boolean the function completed successfully + * * @author Tom N Harris */ public function deletePage($page) { @@ -474,6 +483,7 @@ class Doku_Indexer { * * @param string $page a page name * @return boolean the function completed successfully + * * @author Tom N Harris */ protected function deletePageNoLock($page) { @@ -568,6 +578,7 @@ class Doku_Indexer { * @param string $text plain text * @param boolean $wc are wildcards allowed? * @return array list of words in the text + * * @author Tom N Harris * @author Andreas Gohr */ @@ -676,6 +687,7 @@ class Doku_Indexer { * * @param array $tokens list of words to search for * @return array list of page names with usage counts + * * @author Tom N Harris * @author Andreas Gohr */ @@ -730,6 +742,7 @@ class Doku_Indexer { * @param string $value search term to look for, must be a string or array of strings * @param callback $func comparison function * @return array lists with page names, keys are query values if $value is array + * * @author Tom N Harris * @author Michael Hamann */ @@ -829,6 +842,7 @@ class Doku_Indexer { * @param array $words The query terms. * @param array $result Set to word => array("length*id" ...) * @return array Set to length => array(id ...) + * * @author Tom N Harris */ protected function getIndexWords(&$words, &$result) { @@ -909,6 +923,7 @@ class Doku_Indexer { * * @param string $key list only pages containing the metadata key (optional) * @return array list of page names + * * @author Tom N Harris */ public function getPages($key=null) { @@ -942,6 +957,7 @@ class Doku_Indexer { * @param int $minlen minimum length of words to count * @param string $key metadata key to list. Uses the fulltext index if not given * @return array list of words as the keys and frequency as values + * * @author Tom N Harris */ public function histogram($min=1, $max=0, $minlen=3, $key=null) { @@ -1002,6 +1018,8 @@ class Doku_Indexer { * Lock the indexer. * * @author Tom N Harris + * + * @return bool|string */ protected function lock() { global $conf; @@ -1033,6 +1051,8 @@ class Doku_Indexer { * Release the indexer lock. * * @author Tom N Harris + * + * @return bool */ protected function unlock() { global $conf; @@ -1050,6 +1070,7 @@ class Doku_Indexer { * @param string $idx name of the index * @param string $suffix subpart identifier * @return array list of lines without CR or LF + * * @author Tom N Harris */ protected function getIndex($idx, $suffix) { @@ -1066,6 +1087,7 @@ class Doku_Indexer { * @param string $suffix subpart identifier * @param array $lines list of lines without LF * @return bool If saving succeeded + * * @author Tom N Harris */ protected function saveIndex($idx, $suffix, &$lines) { @@ -1090,6 +1112,7 @@ class Doku_Indexer { * @param string $suffix subpart identifier * @param int $id the line number * @return string a line with trailing whitespace removed + * * @author Tom N Harris */ protected function getIndexKey($idx, $suffix, $id) { @@ -1114,6 +1137,7 @@ class Doku_Indexer { * @param int $id the line number * @param string $line line to write * @return bool If saving succeeded + * * @author Tom N Harris */ protected function saveIndexKey($idx, $suffix, $id, $line) { @@ -1155,6 +1179,7 @@ class Doku_Indexer { * @param string $suffix subpart identifier * @param string $value line to find in the index * @return int|bool line number of the value in the index or false if writing the index failed + * * @author Tom N Harris */ protected function addIndexKey($idx, $suffix, $value) { @@ -1178,6 +1203,8 @@ class Doku_Indexer { * a sorted array of lengths of the words used in the wiki. * * @author YoBoY + * + * @return array */ protected function listIndexLengths() { return idx_listIndexLengths(); @@ -1190,6 +1217,9 @@ class Doku_Indexer { * that there are indices for. * * @author YoBoY + * + * @param array|int $filter + * @return array */ protected function indexLengths($filter) { global $conf; @@ -1216,6 +1246,11 @@ class Doku_Indexer { * Insert or replace a tuple in a line. * * @author Tom N Harris + * + * @param string $line + * @param string $id + * @param int $count + * @return string */ protected function updateTuple($line, $id, $count) { if ($line != ''){ @@ -1237,6 +1272,10 @@ class Doku_Indexer { * * @author Tom N Harris * @author Andreas Gohr + * + * @param array $keys + * @param string $line + * @return array */ protected function parseTuples(&$keys, $line) { $result = array(); @@ -1257,13 +1296,16 @@ class Doku_Indexer { * Sum the counts in a list of tuples. * * @author Tom N Harris + * + * @param string $line + * @return int */ protected function countTuples($line) { $freq = 0; $parts = explode(':', $line); foreach ($parts as $tuple) { if ($tuple === '') continue; - list($pid, $cnt) = explode('*', $tuple); + list(/* $pid */, $cnt) = explode('*', $tuple); $freq += (int)$cnt; } return $freq; @@ -1273,7 +1315,8 @@ class Doku_Indexer { /** * Create an instance of the indexer. * - * @return Doku_Indexer a Doku_Indexer + * @return Doku_Indexer a Doku_Indexer + * * @author Tom N Harris */ function idx_get_indexer() { @@ -1288,6 +1331,7 @@ function idx_get_indexer() { * Returns words that will be ignored. * * @return array list of stop words + * * @author Tom N Harris */ function & idx_get_stopwords() { @@ -1312,7 +1356,8 @@ function & idx_get_stopwords() { * @param string $page name of the page to index * @param boolean $verbose print status messages * @param boolean $force force reindexing even when the index is up to date - * @return boolean the function completed successfully + * @return string|boolean the function completed successfully + * * @author Tom N Harris */ function idx_addPage($page, $verbose=false, $force=false) { @@ -1441,6 +1486,10 @@ function idx_tokenizer($string, $wc=false) { * Read the list of words in an index (if it exists). * * @author Tom N Harris + * + * @param string $idx + * @param string $suffix + * @return array */ function idx_getIndex($idx, $suffix) { global $conf; @@ -1456,6 +1505,8 @@ function idx_getIndex($idx, $suffix) { * a sorted array of lengths of the words used in the wiki. * * @author YoBoY + * + * @return array */ function idx_listIndexLengths() { global $conf; @@ -1510,6 +1561,9 @@ function idx_listIndexLengths() { * that there are indices for. * * @author YoBoY + * + * @param array|int $filter + * @return array */ function idx_indexLengths($filter) { global $conf; @@ -1539,6 +1593,9 @@ function idx_indexLengths($filter) { * not a letter, number, or underscore. * * @author Tom N Harris + * + * @param string $name + * @return string */ function idx_cleanName($name) { $name = utf8_romanize(trim((string)$name)); -- cgit v1.2.3 From e3710957c6b7e12293805a15d0624be7c7054092 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 17:05:40 +0200 Subject: more phpdocs and minor check --- inc/indexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/indexer.php') diff --git a/inc/indexer.php b/inc/indexer.php index ec0c523e0..014c5c5eb 100644 --- a/inc/indexer.php +++ b/inc/indexer.php @@ -1248,7 +1248,7 @@ class Doku_Indexer { * @author Tom N Harris * * @param string $line - * @param string $id + * @param string|int $id * @param int $count * @return string */ -- cgit v1.2.3 From 79e79377626799a77c11aa7849cb9c64305590c8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Jan 2015 10:47:45 +0100 Subject: Remove error supression for file_exists() In an older version of PHP a file_exists() call would issue a warning when the file did not exist. This was fixed in later PHP releases. Since we require PHP 5.3 now, there's no need to supress any error here anymore. This might even give a minor performance boost. --- inc/indexer.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'inc/indexer.php') diff --git a/inc/indexer.php b/inc/indexer.php index 014c5c5eb..a86bfc656 100644 --- a/inc/indexer.php +++ b/inc/indexer.php @@ -1076,7 +1076,7 @@ class Doku_Indexer { protected function getIndex($idx, $suffix) { global $conf; $fn = $conf['indexdir'].'/'.$idx.$suffix.'.idx'; - if (!@file_exists($fn)) return array(); + if (!file_exists($fn)) return array(); return file($fn, FILE_IGNORE_NEW_LINES); } @@ -1118,7 +1118,7 @@ class Doku_Indexer { protected function getIndexKey($idx, $suffix, $id) { global $conf; $fn = $conf['indexdir'].'/'.$idx.$suffix.'.idx'; - if (!@file_exists($fn)) return ''; + if (!file_exists($fn)) return ''; $fh = @fopen($fn, 'r'); if (!$fh) return ''; $ln = -1; @@ -1228,7 +1228,7 @@ class Doku_Indexer { // testing if index files exist only $path = $conf['indexdir']."/i"; foreach ($filter as $key => $value) { - if (@file_exists($path.$key.'.idx')) + if (file_exists($path.$key.'.idx')) $idx[] = $key; } } else { @@ -1339,7 +1339,7 @@ function & idx_get_stopwords() { if (is_null($stopwords)) { global $conf; $swfile = DOKU_INC.'inc/lang/'.$conf['lang'].'/stopwords.txt'; - if(@file_exists($swfile)){ + if(file_exists($swfile)){ $stopwords = file($swfile, FILE_IGNORE_NEW_LINES); }else{ $stopwords = array(); @@ -1364,7 +1364,7 @@ function idx_addPage($page, $verbose=false, $force=false) { $idxtag = metaFN($page,'.indexed'); // check if page was deleted but is still in the index if (!page_exists($page)) { - if (!@file_exists($idxtag)) { + if (!file_exists($idxtag)) { if ($verbose) print("Indexer: $page does not exist, ignoring".DOKU_LF); return false; } @@ -1379,7 +1379,7 @@ function idx_addPage($page, $verbose=false, $force=false) { } // check if indexing needed - if(!$force && @file_exists($idxtag)){ + if(!$force && file_exists($idxtag)){ if(trim(io_readFile($idxtag)) == idx_get_version()){ $last = @filemtime($idxtag); if($last > @filemtime(wikiFN($page))){ @@ -1392,7 +1392,7 @@ function idx_addPage($page, $verbose=false, $force=false) { $indexenabled = p_get_metadata($page, 'internal index', METADATA_RENDER_UNLIMITED); if ($indexenabled === false) { $result = false; - if (@file_exists($idxtag)) { + if (file_exists($idxtag)) { $Indexer = idx_get_indexer(); $result = $Indexer->deletePage($page); if ($result === "locked") { @@ -1494,7 +1494,7 @@ function idx_tokenizer($string, $wc=false) { function idx_getIndex($idx, $suffix) { global $conf; $fn = $conf['indexdir'].'/'.$idx.$suffix.'.idx'; - if (!@file_exists($fn)) return array(); + if (!file_exists($fn)) return array(); return file($fn); } @@ -1515,7 +1515,7 @@ function idx_listIndexLengths() { $docache = false; } else { clearstatcache(); - if (@file_exists($conf['indexdir'].'/lengths.idx') + if (file_exists($conf['indexdir'].'/lengths.idx') && (time() < @filemtime($conf['indexdir'].'/lengths.idx') + $conf['readdircache'])) { if (($lengths = @file($conf['indexdir'].'/lengths.idx', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) !== false) { $idx = array(); @@ -1572,7 +1572,7 @@ function idx_indexLengths($filter) { // testing if index files exist only $path = $conf['indexdir']."/i"; foreach ($filter as $key => $value) { - if (@file_exists($path.$key.'.idx')) + if (file_exists($path.$key.'.idx')) $idx[] = $key; } } else { -- cgit v1.2.3