X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FConsole%2FCreateDoxygen.php;h=1de2cee0400001e7842ad0f7d673d2bb12643d05;hb=4facd1dfdba93ede48ca40b5e146424e6701118b;hp=17da9922ee4ad29044b8010b04bebde2f10d3929;hpb=9b8fb1d550e3902d3b69e7a3477c4a22a5fe0386;p=friendica.git diff --git a/src/Core/Console/CreateDoxygen.php b/src/Core/Console/CreateDoxygen.php index 17da9922ee..1de2cee040 100644 --- a/src/Core/Console/CreateDoxygen.php +++ b/src/Core/Console/CreateDoxygen.php @@ -1,148 +1,148 @@ - - */ -class CreateDoxygen extends \Asika\SimpleConsole\Console -{ - protected $helpOptions = ['h', 'help', '?']; - - protected function getHelp() - { - $help = << [-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; - } - -} + + */ +class CreateDoxygen extends \Asika\SimpleConsole\Console +{ + protected $helpOptions = ['h', 'help', '?']; + + protected function getHelp() + { + $help = << [-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; + } + +}