3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Console;
25 * Description of CreateDoxygen
27 class CreateDoxygen extends \Asika\SimpleConsole\Console
29 protected $helpOptions = ['h', 'help', '?'];
31 protected function getHelp()
34 console createdoxygen - Generate Doxygen headers
36 bin/console createdoxygen <file> [-h|--help|-?] [-v]
39 Outputs the provided file with added Doxygen headers to functions
42 -h|--help|-? Show help information
43 -v Show more debug information.
48 protected function doExecute()
50 if ($this->getOption('v')) {
51 $this->out('Class: ' . __CLASS__);
52 $this->out('Arguments: ' . var_export($this->args, true));
53 $this->out('Options: ' . var_export($this->options, true));
56 if (count($this->args) == 0) {
57 $this->out($this->getHelp());
61 if (count($this->args) > 1) {
62 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
65 $file = $this->getArgument(0);
66 if (!file_exists($file)) {
67 throw new \RuntimeException('Unable to find specified file.');
70 $data = file_get_contents($file);
72 $lines = explode("\n", $data);
76 foreach ($lines AS $line) {
77 $line = rtrim(trim($line, "\r"));
79 if (strstr(strtolower($line), "function")) {
80 $detect = strtolower(trim($line));
81 $detect = implode(" ", explode(" ", $detect));
85 if (substr($detect, 0, 9) == "function ") {
89 if (substr($detect, 0, 19) == "protected function ") {
93 if (substr($detect, 0, 17) == "private function ") {
97 if (substr($detect, 0, 23) == "public static function ") {
101 if (substr($detect, 0, 24) == "private static function ") {
105 if (substr($detect, 0, 10) == "function (") {
109 if ($found && ( trim($previous) == "*/")) {
114 $this->out($this->addDocumentation($line));
125 * Adds a doxygen header
127 * @param string $line The current line of the document
129 * @return string added doxygen header
131 private function addDocumentation($line)
133 $trimmed = ltrim($line);
134 $length = strlen($line) - strlen($trimmed);
135 $space = substr($line, 0, $length);
137 $block = $space . "/**\n" .
139 $space . " *\n"; /**/
142 $left = strpos($line, "(");
143 $line = substr($line, $left + 1);
145 $right = strpos($line, ")");
146 $line = trim(substr($line, 0, $right));
149 $parameters = explode(",", $line);
150 foreach ($parameters AS $parameter) {
151 $parameter = trim($parameter);
152 $splitted = explode("=", $parameter);
154 $block .= $space . " * @param " . trim($splitted[0], "& ") . "\n";
156 if (count($parameters) > 0) $block .= $space . " *\n";
159 $block .= $space . " * @return \n" .