]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Console/CreateDoxygen.php
Line feeds fixed, not change in functionality
[friendica.git] / src / Core / Console / CreateDoxygen.php
index 17da9922ee4ad29044b8010b04bebde2f10d3929..b60116db3c620dd4064c390bd1e0472e0ffc0b22 100644 (file)
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-/**\r
- * Description of CreateDoxygen\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class CreateDoxygen extends \Asika\SimpleConsole\Console\r
-{\r
-       protected $helpOptions = ['h', 'help', '?'];\r
-\r
-       protected function getHelp()\r
-       {\r
-               $help = <<<HELP\r
-console createdoxygen - Generate Doxygen headers\r
-Usage\r
-       bin/console createdoxygen <file> [-h|--help|-?] [-v]\r
-\r
-Description\r
-       Outputs the provided file with added Doxygen headers to functions\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
-                       $this->out($this->getHelp());\r
-                       return 0;\r
-               }\r
-\r
-               if (count($this->args) > 1) {\r
-                       throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
-               }\r
-\r
-               $file = $this->getArgument(0);\r
-               if (!file_exists($file)) {\r
-                       throw new \RuntimeException('Unable to find specified file.');\r
-               }\r
-\r
-               $data = file_get_contents($file);\r
-\r
-               $lines = explode("\n", $data);\r
-\r
-               $previous = "";\r
-\r
-               foreach ($lines AS $line) {\r
-                       $line = rtrim(trim($line, "\r"));\r
-\r
-                       if (strstr(strtolower($line), "function")) {\r
-                               $detect = strtolower(trim($line));\r
-                               $detect = implode(" ", explode(" ", $detect));\r
-\r
-                               $found = false;\r
-\r
-                               if (substr($detect, 0, 9) == "function ") {\r
-                                       $found = true;\r
-                               }\r
-\r
-                               if (substr($detect, 0, 19) == "protected function ") {\r
-                                       $found = true;\r
-                               }\r
-\r
-                               if (substr($detect, 0, 17) == "private function ") {\r
-                                       $found = true;\r
-                               }\r
-\r
-                               if (substr($detect, 0, 23) == "public static function ") {\r
-                                       $found = true;\r
-                               }\r
-\r
-                               if (substr($detect, 0, 24) == "private static function ") {\r
-                                       $found = true;\r
-                               }\r
-\r
-                               if (substr($detect, 0, 10) == "function (") {\r
-                                       $found = false;\r
-                               }\r
-\r
-                               if ($found && ( trim($previous) == "*/")) {\r
-                                       $found = false;\r
-                               }\r
-\r
-                               if ($found) {\r
-                                       $this->out($this->addDocumentation($line));\r
-                               }\r
-                       }\r
-                       $this->out($line);\r
-                       $previous = $line;\r
-               }\r
-\r
-               return 0;\r
-       }\r
-\r
-       /**\r
-        * @brief Adds a doxygen header\r
-        *\r
-        * @param string $line The current line of the document\r
-        *\r
-        * @return string added doxygen header\r
-        */\r
-       private function addDocumentation($line)\r
-       {\r
-               $trimmed = ltrim($line);\r
-               $length = strlen($line) - strlen($trimmed);\r
-               $space = substr($line, 0, $length);\r
-\r
-               $block = $space . "/**\n" .\r
-                       $space . " * @brief \n" .\r
-                       $space . " *\n"; /**/\r
-\r
-\r
-               $left = strpos($line, "(");\r
-               $line = substr($line, $left + 1);\r
-\r
-               $right = strpos($line, ")");\r
-               $line = trim(substr($line, 0, $right));\r
-\r
-               if ($line != "") {\r
-                       $parameters = explode(",", $line);\r
-                       foreach ($parameters AS $parameter) {\r
-                               $parameter = trim($parameter);\r
-                               $splitted = explode("=", $parameter);\r
-\r
-                               $block .= $space . " * @param " . trim($splitted[0], "& ") . "\n";\r
-                       }\r
-                       if (count($parameters) > 0) $block .= $space . " *\n";\r
-               }\r
-\r
-               $block .= $space . " * @return \n" .\r
-                       $space . " */\n";\r
-\r
-               return $block;\r
-       }\r
-\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+/**
+ * Description of CreateDoxygen
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class CreateDoxygen extends \Asika\SimpleConsole\Console
+{
+       protected $helpOptions = ['h', 'help', '?'];
+
+       protected function getHelp()
+       {
+               $help = <<<HELP
+console createdoxygen - Generate Doxygen headers
+Usage
+       bin/console createdoxygen <file> [-h|--help|-?] [-v]
+
+Description
+       Outputs the provided file with added Doxygen headers to functions
+
+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) {
+                       $this->out($this->getHelp());
+                       return 0;
+               }
+
+               if (count($this->args) > 1) {
+                       throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+               }
+
+               $file = $this->getArgument(0);
+               if (!file_exists($file)) {
+                       throw new \RuntimeException('Unable to find specified file.');
+               }
+
+               $data = file_get_contents($file);
+
+               $lines = explode("\n", $data);
+
+               $previous = "";
+
+               foreach ($lines AS $line) {
+                       $line = rtrim(trim($line, "\r"));
+
+                       if (strstr(strtolower($line), "function")) {
+                               $detect = strtolower(trim($line));
+                               $detect = implode(" ", explode(" ", $detect));
+
+                               $found = false;
+
+                               if (substr($detect, 0, 9) == "function ") {
+                                       $found = true;
+                               }
+
+                               if (substr($detect, 0, 19) == "protected function ") {
+                                       $found = true;
+                               }
+
+                               if (substr($detect, 0, 17) == "private function ") {
+                                       $found = true;
+                               }
+
+                               if (substr($detect, 0, 23) == "public static function ") {
+                                       $found = true;
+                               }
+
+                               if (substr($detect, 0, 24) == "private static function ") {
+                                       $found = true;
+                               }
+
+                               if (substr($detect, 0, 10) == "function (") {
+                                       $found = false;
+                               }
+
+                               if ($found && ( trim($previous) == "*/")) {
+                                       $found = false;
+                               }
+
+                               if ($found) {
+                                       $this->out($this->addDocumentation($line));
+                               }
+                       }
+                       $this->out($line);
+                       $previous = $line;
+               }
+
+               return 0;
+       }
+
+       /**
+        * @brief Adds a doxygen header
+        *
+        * @param string $line The current line of the document
+        *
+        * @return string added doxygen header
+        */
+       private function addDocumentation($line)
+       {
+               $trimmed = ltrim($line);
+               $length = strlen($line) - strlen($trimmed);
+               $space = substr($line, 0, $length);
+
+               $block = $space . "/**\n" .
+                       $space . " * @brief \n" .
+                       $space . " *\n"; /**/
+
+
+               $left = strpos($line, "(");
+               $line = substr($line, $left + 1);
+
+               $right = strpos($line, ")");
+               $line = trim(substr($line, 0, $right));
+
+               if ($line != "") {
+                       $parameters = explode(",", $line);
+                       foreach ($parameters AS $parameter) {
+                               $parameter = trim($parameter);
+                               $splitted = explode("=", $parameter);
+
+                               $block .= $space . " * @param " . trim($splitted[0], "& ") . "\n";
+                       }
+                       if (count($parameters) > 0) $block .= $space . " *\n";
+               }
+
+               $block .= $space . " * @return \n" .
+                       $space . " */\n";
+
+               return $block;
+       }
+
+}