]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Console/DocBloxErrorChecker.php
Preload Adapter Fix
[friendica.git] / src / Core / Console / DocBloxErrorChecker.php
index 2a9aa024f96e1aeb312ec1a3cd5f4389312c92a7..506e48f0fd5607d0d6d7a57f360780d9cfc0b263 100644 (file)
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-/**\r
- * When I installed docblox, I had the experience that it does not generate any output at all.\r
- * This script may be used to find that kind of problems with the documentation build process.\r
- * If docblox generates output, use another approach for debugging.\r
- *\r
- * Basically, docblox takes a list of files to build documentation from. This script assumes there is a file or set of files\r
- * breaking the build when it is included in that list. It tries to calculate the smallest list containing these files.\r
- * Unfortunatly, the original problem is NP-complete, so what the script does is a best guess only.\r
- *\r
- * So it starts with a list of all files in the project.\r
- * If that list can't be build, it cuts it in two parts and tries both parts independently. If only one of them breaks,\r
- * it takes that one and tries the same independently. If both break, it assumes this is the smallest set. This assumption\r
- * is not necessarily true. Maybe the smallest set consists of two files and both of them were in different parts when\r
- * the list was divided, but by now it is my best guess. To make this assumption better, the list is shuffled after every step.\r
- *\r
- * After that, the script tries to remove a file from the list. It tests if the list breaks and if so, it\r
- * assumes that the file it removed belongs to the set of erroneous files.\r
- * This is done for all files, so, in the end removing one file leads to a working doc build.\r
- *\r
- * @author Alexander Kampmann\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class DocBloxErrorChecker extends \Asika\SimpleConsole\Console\r
-{\r
-\r
-       protected $helpOptions = ['h', 'help', '?'];\r
-\r
-       protected function getHelp()\r
-       {\r
-               $help = <<<HELP\r
-console docbloxerrorchecker - Checks the file tree for docblox errors\r
-Usage\r
-       bin/console docbloxerrorchecker [-h|--help|-?] [-v]\r
-\r
-Options\r
-    -h|--help|-? Show help information\r
-    -v           Show more debug information.\r
-HELP;\r
-               return $help;\r
-       }\r
-\r
-       protected function doExecute()\r
-       {\r
-               if ($this->getOption('v')) {\r
-                       $this->out('Class: ' . __CLASS__);\r
-                       $this->out('Arguments: ' . var_export($this->args, true));\r
-                       $this->out('Options: ' . var_export($this->options, true));\r
-               }\r
-\r
-               if (count($this->args) > 0) {\r
-                       throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
-               }\r
-\r
-               if (!$this->commandExists('docblox')) {\r
-                       throw new \RuntimeException('DocBlox isn\'t available.');\r
-               }\r
-\r
-               //return from util folder to frindica base dir\r
-               $dir = get_app()->get_basepath();\r
-\r
-               //stack for dirs to search\r
-               $dirstack = [];\r
-               //list of source files\r
-               $filelist = [];\r
-\r
-               //loop over all files in $dir\r
-               while ($dh = opendir($dir)) {\r
-                       while ($file = readdir($dh)) {\r
-                               if (is_dir($dir . "/" . $file)) {\r
-                                       //add to directory stack\r
-                                       if (strpos($file, '.') !== 0) {\r
-                                               array_push($dirstack, $dir . "/" . $file);\r
-                                               $this->out('dir ' . $dir . '/' . $file);\r
-                                       }\r
-                               } else {\r
-                                       //test if it is a source file and add to filelist\r
-                                       if (substr($file, strlen($file) - 4) == ".php") {\r
-                                               array_push($filelist, $dir . "/" . $file);\r
-                                               $this->out($dir . '/' . $file);\r
-                                       }\r
-                               }\r
-                       }\r
-                       //look at the next dir\r
-                       $dir = array_pop($dirstack);\r
-               }\r
-\r
-               //check the entire set\r
-               if ($this->runs($filelist)) {\r
-                       throw new \RuntimeException("I can not detect a problem.");\r
-               }\r
-\r
-               //check half of the set and discard if that half is okay\r
-               $res = $filelist;\r
-               $i = count($res);\r
-               do {\r
-                       $this->out($i . '/' . count($filelist) . ' elements remaining.');\r
-                       $res = $this->reduce($res, count($res) / 2);\r
-                       shuffle($res);\r
-                       $i = count($res);\r
-               } while (count($res) < $i);\r
-\r
-               //check one file after another\r
-               $needed = [];\r
-\r
-               while (count($res) != 0) {\r
-                       $file = array_pop($res);\r
-\r
-                       if ($this->runs(array_merge($res, $needed))) {\r
-                               $this->out('needs: ' . $file . ' and file count ' . count($needed));\r
-                               array_push($needed, $file);\r
-                       }\r
-               }\r
-\r
-               $this->out('Smallest Set is: ' . $this->namesList($needed) . ' with ' . count($needed) . ' files. ');\r
-\r
-               return 0;\r
-       }\r
-\r
-       private function commandExists($command)\r
-       {\r
-               $prefix = strpos(strtolower(PHP_OS),'win') > -1 ? 'where' : 'which';\r
-               exec("{$prefix} {$command}", $output = [], $returnVal = 0);\r
-               return $returnVal === 0;\r
-       }\r
-\r
-       /**\r
-        * This function generates a comma separated list of file names.\r
-        *\r
-        * @package util\r
-        *\r
-        * @param array $fileset Set of file names\r
-        *\r
-        * @return string comma-separated list of the file names\r
-        */\r
-       private function namesList($fileset)\r
-       {\r
-               return implode(',', $fileset);\r
-       }\r
-\r
-       /**\r
-        * This functions runs phpdoc on the provided list of files\r
-        * @package util\r
-        *\r
-        * @param array $fileset Set of filenames\r
-        *\r
-        * @return bool true, if that set can be built\r
-        */\r
-       private function runs($fileset)\r
-       {\r
-               $fsParam = $this->namesList($fileset);\r
-               $this->exec('docblox -t phpdoc_out -f ' . $fsParam);\r
-               if (file_exists("phpdoc_out/index.html")) {\r
-                       $this->out('Subset ' . $fsParam . ' is okay.');\r
-                       $this->exec('rm -r phpdoc_out');\r
-                       return true;\r
-               } else {\r
-                       $this->out('Subset ' . $fsParam . ' failed.');\r
-                       return false;\r
-               }\r
-       }\r
-\r
-       /**\r
-        * This functions cuts down a fileset by removing files until it finally works.\r
-        * it was meant to be recursive, but php's maximum stack size is to small. So it just simulates recursion.\r
-        *\r
-        * In that version, it does not necessarily generate the smallest set, because it may not alter the elements order enough.\r
-        *\r
-        * @package util\r
-        *\r
-        * @param array $fileset set of filenames\r
-        * @param int $ps number of files in subsets\r
-        *\r
-        * @return array a part of $fileset, that crashes\r
-        */\r
-       private function reduce($fileset, $ps)\r
-       {\r
-               //split array...\r
-               $parts = array_chunk($fileset, $ps);\r
-               //filter working subsets...\r
-               $parts = array_filter($parts, [$this, 'runs']);\r
-               //melt remaining parts together\r
-               if (is_array($parts)) {\r
-                       return array_reduce($parts, "array_merge", []);\r
-               }\r
-               return [];\r
-       }\r
-\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+/**
+ * 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 erroneous files.
+ * This is done for all files, so, in the end removing one file leads to a working doc build.
+ *
+ * @author Alexander Kampmann
+ * @author Hypolite Petovan <hypolite@mrpetovan.com>
+ */
+class DocBloxErrorChecker extends \Asika\SimpleConsole\Console
+{
+
+       protected $helpOptions = ['h', 'help', '?'];
+
+       protected function getHelp()
+       {
+               $help = <<<HELP
+console docbloxerrorchecker - Checks the file tree for docblox errors
+Usage
+       bin/console docbloxerrorchecker [-h|--help|-?] [-v]
+
+Options
+    -h|--help|-? Show help information
+    -v           Show more debug information.
+HELP;
+               return $help;
+       }
+
+       protected function doExecute()
+       {
+               if ($this->getOption('v')) {
+                       $this->out('Class: ' . __CLASS__);
+                       $this->out('Arguments: ' . var_export($this->args, true));
+                       $this->out('Options: ' . var_export($this->options, true));
+               }
+
+               if (count($this->args) > 0) {
+                       throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+               }
+
+               if (!$this->commandExists('docblox')) {
+                       throw new \RuntimeException('DocBlox isn\'t available.');
+               }
+
+               $dir = \get_app()->getBasePath();
+
+               //stack for dirs to search
+               $dirstack = [];
+               //list of source files
+               $filelist = [];
+
+               //loop over all files in $dir
+               while ($dh = opendir($dir)) {
+                       while ($file = readdir($dh)) {
+                               if (is_dir($dir . "/" . $file)) {
+                                       //add to directory stack
+                                       if (strpos($file, '.') !== 0) {
+                                               array_push($dirstack, $dir . "/" . $file);
+                                               $this->out('dir ' . $dir . '/' . $file);
+                                       }
+                               } else {
+                                       //test if it is a source file and add to filelist
+                                       if (substr($file, strlen($file) - 4) == ".php") {
+                                               array_push($filelist, $dir . "/" . $file);
+                                               $this->out($dir . '/' . $file);
+                                       }
+                               }
+                       }
+                       //look at the next dir
+                       $dir = array_pop($dirstack);
+               }
+
+               //check the entire set
+               if ($this->runs($filelist)) {
+                       throw new \RuntimeException("I can not detect a problem.");
+               }
+
+               //check half of the set and discard if that half is okay
+               $res = $filelist;
+               $i = count($res);
+               do {
+                       $this->out($i . '/' . count($filelist) . ' elements remaining.');
+                       $res = $this->reduce($res, count($res) / 2);
+                       shuffle($res);
+                       $i = count($res);
+               } while (count($res) < $i);
+
+               //check one file after another
+               $needed = [];
+
+               while (count($res) != 0) {
+                       $file = array_pop($res);
+
+                       if ($this->runs(array_merge($res, $needed))) {
+                               $this->out('needs: ' . $file . ' and file count ' . count($needed));
+                               array_push($needed, $file);
+                       }
+               }
+
+               $this->out('Smallest Set is: ' . $this->namesList($needed) . ' with ' . count($needed) . ' files. ');
+
+               return 0;
+       }
+
+       private function commandExists($command)
+       {
+               $prefix = strpos(strtolower(PHP_OS),'win') > -1 ? 'where' : 'which';
+               exec("{$prefix} {$command}", $output, $returnVal);
+               return $returnVal === 0;
+       }
+
+       /**
+        * This function generates a comma separated list of file names.
+        *
+        * @param array $fileset Set of file names
+        *
+        * @return string comma-separated list of the file names
+        */
+       private function namesList($fileset)
+       {
+               return implode(',', $fileset);
+       }
+
+       /**
+        * This functions runs phpdoc on the provided list of files
+        *
+        * @param array $fileset Set of filenames
+        *
+        * @return bool true, if that set can be built
+        */
+       private function runs($fileset)
+       {
+               $fsParam = $this->namesList($fileset);
+               $this->exec('docblox -t phpdoc_out -f ' . $fsParam);
+               if (file_exists("phpdoc_out/index.html")) {
+                       $this->out('Subset ' . $fsParam . ' is okay.');
+                       $this->exec('rm -r phpdoc_out');
+                       return true;
+               } else {
+                       $this->out('Subset ' . $fsParam . ' failed.');
+                       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.
+        *
+        * @param array $fileset set of filenames
+        * @param int $ps number of files in subsets
+        *
+        * @return array a part of $fileset, that crashes
+        */
+       private function reduce($fileset, $ps)
+       {
+               //split array...
+               $parts = array_chunk($fileset, $ps);
+               //filter working subsets...
+               $parts = array_filter($parts, [$this, 'runs']);
+               //melt remaining parts together
+               if (is_array($parts)) {
+                       return array_reduce($parts, "array_merge", []);
+               }
+               return [];
+       }
+
+}