diff options
author | Simon L'nu <simon.lnu@gmail.com> | 2012-03-02 04:07:23 -0500 |
---|---|---|
committer | Simon L'nu <simon.lnu@gmail.com> | 2012-03-02 04:07:23 -0500 |
commit | f0fdd1a163b6bc7213eeb48c6ee9025087bb0032 (patch) | |
tree | 2e7855a389313397b310a70b0e6072a5ba6dcce1 /util/docblox_errorchecker.php | |
parent | b7ab2a2fc92bbd7ec3a506e18f950579e10719eb (diff) | |
parent | 90bdddca0d1b2e2128646d1f698b6d514e748001 (diff) | |
download | volse-hubzilla-f0fdd1a163b6bc7213eeb48c6ee9025087bb0032.tar.gz volse-hubzilla-f0fdd1a163b6bc7213eeb48c6ee9025087bb0032.tar.bz2 volse-hubzilla-f0fdd1a163b6bc7213eeb48c6ee9025087bb0032.zip |
Merge branch 'master', remote-tracking branch 'remotes/upstream/master'
* remotes/upstream/master:
item table update for file feature
probe for very old (0.97 or 1.0) RSS feed with an incorrect or generic content-type
diabook commit
conversation: remove templating items in code and move it to template.
Enabled automated doc building. Changes: -build.xml, phing build file -@package tags at acl_selector.php and db_update.php -added documentation and some IDE files to .gitignore -automated tool to find files that corrupt the doc build process -removed ansi characters from SSH1.php, docBlox could not handle them
template proc: avoid a notice and allow template name to include to be passed with a variable value
show relation in contact_template
admin: fix small string
fix visualization in groupeditor
less html in mod/group.php, template for group members editor, quattro theme for group edit.
* master:
Diffstat (limited to 'util/docblox_errorchecker.php')
-rw-r--r-- | util/docblox_errorchecker.php | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/util/docblox_errorchecker.php b/util/docblox_errorchecker.php new file mode 100644 index 000000000..af4c76444 --- /dev/null +++ b/util/docblox_errorchecker.php @@ -0,0 +1,145 @@ +<?php +/** + * When I installed docblox, I had the experience that it does not generate any output at all. + * This script may be used to find that kind of problems with the documentation build process. + * If docblox generates output, use another approach for debugging. + * + * Basically, docblox takes a list of files to build documentation from. This script assumes there is a file or set of files + * breaking the build when it is included in that list. It tries to calculate the smallest list containing these files. + * Unfortunatly, the original problem is NP-complete, so what the script does is a best guess only. + * + * So it starts with a list of all files in the project. + * If that list can't be build, it cuts it in two parts and tries both parts independently. If only one of them breaks, + * it takes that one and tries the same independently. If both break, it assumes this is the smallest set. This assumption + * is not necessarily true. Maybe the smallest set consists of two files and both of them were in different parts when + * the list was divided, but by now it is my best guess. To make this assumption better, the list is shuffled after every step. + * + * After that, the script tries to remove a file from the list. It tests if the list breaks and if so, it + * assumes that the file it removed belongs to the set of errorneous files. + * This is done for all files, so, in the end removing one file leads to a working doc build. + * + * @package util + * @author Alexander Kampmann + */ + +/** + * This function generates a comma seperated list of file names. + * + * @package util + * + * @param array $fileset Set of file names + * + * @return string comma-seperated list of the file names + */ +function namesList($fileset) { + $fsparam=""; + foreach($fileset as $file) { + $fsparam=$fsparam.",".$file; + } + return $fsparam; +}; + +/** + * This functions runs phpdoc on the provided list of files + * @package util + * + * @param array $fileset Set of filenames + * + * @return bool true, if that set can be built + */ +function runs($fileset) { + $fsParam=namesList($fileset); + exec('docblox -t phpdoc_out -f '.$fsParam); + if(file_exists("phpdoc_out/index.html")) { + echo "\n Subset ".$fsParam." is okay. \n"; + exec('rm -r phpdoc_out'); + return true; + } else { + echo "\n Subset ".$fsParam." failed. \n"; + return false; + } +}; + +/** + * This functions cuts down a fileset by removing files until it finally works. + * it was meant to be recursive, but php's maximum stack size is to small. So it just simulates recursion. + * + * In that version, it does not necessarily generate the smallest set, because it may not alter the elements order enough. + * + * @package util + * + * @param array $fileset set of filenames + * @param int $ps number of files in subsets + * + * @return array a part of $fileset, that crashes + */ +function reduce($fileset, $ps) { + //split array... + $parts=array_chunk($fileset, $ps); + //filter working subsets... + $parts=array_filter($parts, "runs"); + //melt remaining parts together + if(is_array($parts)) { + return array_reduce($parts, "array_merge", array()); + } + return array(); +}; + +//return from util folder to frindica base dir +$dir='..'; + +//stack for dirs to search +$dirstack=array(); +//list of source files +$filelist=array(); + +//loop over all files in $dir +while($dh=opendir($dir)) { + while($file=readdir($dh)) { + if(is_dir($dir."/".$file)) { + //add to directory stack + if($file!=".." && $file!=".") { + array_push($dirstack, $dir."/".$file); + echo "dir ".$dir."/".$file."\n"; + } + } else { + //test if it is a source file and add to filelist + if(substr($file, strlen($file)-4)==".php") { + array_push($filelist, $dir."/".$file); + echo $dir."/".$file."\n"; + } + } + } + //look at the next dir + $dir=array_pop($dirstack); +} + +//check the entire set +if(runs($filelist)) { + echo "I can not detect a problem. \n"; + exit; +} + +//check half of the set and discard if that half is okay +$res=$filelist; +$i=0; +do { + $i=count($res); + echo $i."/".count($fileset)." elements remaining. \n"; + $res=reduce($res, count($res)/2); + shuffle($res); +} while(count($res)<$i); + +//check one file after another +$needed=array(); + +while(count($res)!=0) { + $file=array_pop($res); + + if(runs(array_merge($res, $needed))) { + echo "needs: ".$file." and file count ".count($needed); + array_push($needed, $file); + } +} + +echo "\nSmallest Set is: ".namesList($needed)." with ".count($needed)." files. "; |