3 namespace Friendica\Core\Console;
6 * Description of CreateDoxygen
8 * @author Hypolite Petovan <hypolite@mrpetovan.com>
10 class CreateDoxygen extends \Asika\SimpleConsole\Console
12 protected $helpOptions = ['h', 'help', '?'];
14 protected function getHelp()
17 console createdoxygen - Generate Doxygen headers
19 bin/console createdoxygen <file> [-h|--help|-?] [-v]
22 Outputs the provided file with added Doxygen headers to functions
25 -h|--help|-? Show help information
26 -v Show more debug information.
31 protected function doExecute()
33 if ($this->getOption('v')) {
34 $this->out('Class: ' . __CLASS__);
35 $this->out('Arguments: ' . var_export($this->args, true));
36 $this->out('Options: ' . var_export($this->options, true));
39 if (count($this->args) == 0) {
40 $this->out($this->getHelp());
44 if (count($this->args) > 1) {
45 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
48 $file = $this->getArgument(0);
49 if (!file_exists($file)) {
50 throw new \RuntimeException('Unable to find specified file.');
53 $data = file_get_contents($file);
55 $lines = explode("\n", $data);
59 foreach ($lines AS $line) {
60 $line = rtrim(trim($line, "\r"));
62 if (strstr(strtolower($line), "function")) {
63 $detect = strtolower(trim($line));
64 $detect = implode(" ", explode(" ", $detect));
68 if (substr($detect, 0, 9) == "function ") {
72 if (substr($detect, 0, 19) == "protected function ") {
76 if (substr($detect, 0, 17) == "private function ") {
80 if (substr($detect, 0, 23) == "public static function ") {
84 if (substr($detect, 0, 24) == "private static function ") {
88 if (substr($detect, 0, 10) == "function (") {
92 if ($found && ( trim($previous) == "*/")) {
97 $this->out($this->addDocumentation($line));
108 * @brief Adds a doxygen header
110 * @param string $line The current line of the document
112 * @return string added doxygen header
114 private function addDocumentation($line)
116 $trimmed = ltrim($line);
117 $length = strlen($line) - strlen($trimmed);
118 $space = substr($line, 0, $length);
120 $block = $space . "/**\n" .
121 $space . " * @brief \n" .
122 $space . " *\n"; /**/
125 $left = strpos($line, "(");
126 $line = substr($line, $left + 1);
128 $right = strpos($line, ")");
129 $line = trim(substr($line, 0, $right));
132 $parameters = explode(",", $line);
133 foreach ($parameters AS $parameter) {
134 $parameter = trim($parameter);
135 $splitted = explode("=", $parameter);
137 $block .= $space . " * @param " . trim($splitted[0], "& ") . "\n";
139 if (count($parameters) > 0) $block .= $space . " *\n";
142 $block .= $space . " * @return \n" .